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,151 +0,0 @@
1
- ---
2
- name: causal-inference
3
- description: |
4
- 触发:相关≠因果、干预/反事实推理、do-演算、因果图(DAG)建模、混淆变量识别、政策/处理效应评估;或为模型可解释性、分布外泛化、数据生成过程(DGP)建模而需显式因果假设时调用。
5
- English: Trigger when a problem concerns correlation≠causation, intervention/counterfactual reasoning, do-calculus, causal DAG modeling, confounder identification, policy/treatment effect estimation; or needs explicit causal assumptions for model interpretability, out-of-distribution generalization, or data-generating process modeling.
6
- ---
7
-
8
- > **语言路由**:若用户消息为英文,请读取并遵循同目录下的 `SKILL.en.md`,按其操作规程以英文输出;中文消息则继续使用本文件。
9
-
10
- # 🔗 因果推断思想 / Causal Inference
11
-
12
- > "相关不等于因果——但因果可以理清。关键区别:'看到X时Y如何'≠'如果做了X会怎样'"
13
- > "Correlation is not causation — but causation can be sorted out. Key distinction: 'how is Y when we see X' ≠ 'what if we did X'"
14
- >
15
- > —— 因果推断、结构因果模型、反事实推理
16
- > —— Causal Inference, Structural Causal Models, Counterfactual Reasoning
17
-
18
- ## 核心原则 / Core Principle
19
-
20
- **因果推断回答的问题超出概率论的表达能力:概率论能回答"看到 X 时 Y 如何",但不能回答"如果做了 X 会怎样"。Pearl 因果层级将推理分为三层,每层需要更强的建模假设。**
21
-
22
- **Causal inference answers questions beyond probability's expressive power: probability answers "how is Y when we see X," not "what if we did X." Pearl's causal hierarchy has three levels, each requiring stronger modeling assumptions.**
23
-
24
- > **数学形式化 / Mathematical Formalization**
25
- >
26
- > Pearl 因果层级 / Causal Hierarchy:
27
- > - **Level 1 关联 / Association**:P(y|x) —— 看到/观察 / Seeing
28
- > - **Level 2 干预 / Intervention**:P(y|do(x)) —— 做/干预 / Doing
29
- > - **Level 3 反事实 / Counterfactual**:P(y_x|x',y') —— 想/回顾 / Imagining
30
- >
31
- > **do(x) ≠ 条件化 x**:do(x) 切断所有指向 X 的箭头(图手术),条件化 x 不切断任何箭头。后门调整 / back-door adjustment:P(y|do(x)) = Σ_z P(y|x,z)P(z)
32
- >
33
- > **潜在结果 / Potential Outcomes (Neyman-Rubin)**:Y(x) 为"若施干预 X=x 时 Y 的取值";个体效应 τ_i = Y_i(1)-Y_i(0),平均处理效应 ATE = E[Y(1)]-E[Y(0)] = E[Y|do(X=1)] - E[Y|do(X=0)]。
34
- >
35
- > **结构因果模型 / SCM**:Y := f(X, Z, U),U 为外生变量;DAG + 结构方程共同确定反事实 Y_x = f(x, Z, U)。
36
- >
37
- > **d-分离 / d-Separation**:路径被 Z 阻断 ⟺ 链/叉中点 ∈ Z,或 collider X→C←Y 且 C 及其后代 ∉ Z。d-分离 X⊥_G Y|Z 蕴含条件独立,是图上读出因果假设的工具。
38
- >
39
- > **do-演算三规则 / Do-calculus**(在修正图上用 d-分离判断):
40
- > - 规则 1(插入/删除观察):若 Y ⊥ Z | X 在删去所有指向 X 的箭头后的图中成立,则 P(y|do(x),z) = P(y|do(x))
41
- > - 规则 2(干预与观察互换):若 Y ⊥ Z | X 在删去所有指向 X 的箭头并删去所有从 Z 出发的箭头后的图中成立,则 P(y|do(x),do(z)) = P(y|do(x),z)
42
- > - 规则 3(插入/删除干预):若 Y ⊥ Z | X 在删去所有指向 X 的箭头并删去所有从 Z 到 X 的路径上的箭头后的图中成立,则 P(y|do(x),do(z)) = P(y|do(x))
43
- >
44
- > **因果推理需显式因果模型,不能仅靠数据推导。DAG 编码因果假设,do-演算将干预表达式转化为可观测量。**
45
- >
46
- > 详细数学依据见 `original-texts.md`
47
-
48
- ## GPU 友好性 / GPU-Friendliness(横切检查)
49
-
50
- 当因果推断用于**模型可解释性 / 分布外泛化 / 数据生成过程建模**并需大规模估计时,方法本身要过 `../../references/gpu-friendly-math.md` 八维门:
51
-
52
- - **效应估计 / 调整回归**:后门调整、IPW、双重机器学习的条件期望/regression 全是批量 GEMM,张量化、可融合、低精度可行——**友好**(见 `../../references/books/optimization-ml.md`)。
53
- - **条件独立检验**:高维条件独立检验含精度阵(协方差逆)求逆 $O(p^3)$,可改 **低秩/对角近似**或迭代求解器——**可改造**(见 `../../references/books/matrix-analysis.md`)。
54
- - **精确因果发现(DAG 搜索)**:DAG 空间随节点数超指数增长,精确打分搜索 NP-hard、不可微、串行——典型"美但不可算"反模式。
55
- - **改造手法**:NOTEARS 式**连续松弛**(无环性 $h(W)=\text{tr}(e^{W\circ W})-p=0$)把离散图搜索变成可微优化;或 MCMC/贪心+打分作启发式近似。
56
- - **反事实/SCM 仿真**:结构方程前向模拟可批量并行;但个体反事实依赖外生 U 的识别,警惕串行依赖。
57
-
58
- 八维最低判定(正式术语):**张量化**看样本/干预/候选图能否批量处理;**GEMM 可映射**看调整回归与表示学习是否落矩阵乘;**复杂度**看因果发现是否避开超指数 DAG 搜索;**显存与 KV-Cache**看精度阵、候选图和中间反事实是否可压缩;**低精度稳定**看 IPW 权重、协方差逆和 logit 是否稳健;**并行与通信**看多环境/多干预估计能否并行;**稀疏结构**看 DAG/SCM 是否结构化稀疏;**算子融合**看打分、mask、loss 能否融合。
59
-
60
- > 配合 `../../references/books/optimization-ml.md`(干预估计/regression)与 `../../references/books/matrix-analysis.md`(条件独立/低秩精度阵)。
61
-
62
- ## 不适用场景 / When NOT to Use
63
-
64
- - **纯预测任务且无因果问题**(只需 P(y|x),不关心"为什么")——关联足够,因果多余。
65
- - **无可编码的因果假设**(画不出合理 DAG,因果方向不确定)——没有显式假设就没有因果结论。
66
- - **确定性系统且无变异**(输入严格唯一映射输出)——因果已被机制完全描述,无需概率因果框架。
67
-
68
- ## 何时使用 / When to Use
69
-
70
- - 需要知道干预的效果("做了 X,Y 会怎样?")——需 P(y|do(x)) 而非 P(y|x)。
71
- - 需要区分原因与混淆变量(X 导致 Y,还是 Z 同时导致 X 和 Y?)——DAG 识别混淆路径。
72
- - 需要反事实推理("若当时没做 A 结果会怎样?")——Level 3 需结构方程。
73
- - 需要政策/处理效应评估(RCT 不可行时的后门调整、IV、双重差分)。
74
- - 需要中介分析(拆分 X→M→Y 的直接与间接效应)。
75
- - 需要为**模型可解释性 / 分布外泛化**建模数据生成过程(DGP),把预测器的关联变成可干预的因果机制。
76
-
77
- ## 方法流程 / Method
78
-
79
- ### 第一步:构建因果 DAG / Construct the Causal DAG
80
- 明确所有变量,画因果箭头编码直接原因假设,检查无环性。识别原因变量 X(干预对象)、结果 Y(效应)、混淆 Z(X、Y 共同原因)、中介 M(X→M→Y)。箭头 X→Y 表示"X 是 Y 的直接原因",方向编码因果假设。DAG 必须有向无环——存在环路则因果方向不确定,需重新建模。**关键**:是否有足够领域知识编码因果方向?结论完全依赖 DAG 正确性。
81
-
82
- ### 第二步:识别混淆变量 / Identify Confounders
83
- 混淆变量同时影响 X 和 Y,创造虚假关联——不调整则效应估计有偏。**定义**:Z 是混淆 ⟺ Z 是 X、Y 的共同原因(Z→X 且 Z→Y)。**DAG 识别法**:找 X、Y 的所有共同祖先。**后门路径** X←Z→Y 创造非因果关联需阻断。**关键**:所有混淆是否可观测?存在未观测混淆则后门调整不可用,需前门准则或工具变量。
84
-
85
- ### 第三步:选择识别策略 / Choose Identification Strategy
86
- 据混淆可观测性,选择从观测数据计算 P(y|do(x)) 的策略:
87
- - **后门准则 / Back-door**:若 ∃ S 阻断 X→Y 所有后门路径且 S 不含 X 的后代,则 P(y|do(x)) = Σ_s P(y|x,S=s)·P(S=s)。
88
- - **前门准则 / Front-door**:混淆不可观测但中介 M 可观测,且 X→M 无后门、M 阻断 X→Y 所有后门路径,则 P(y|do(x)) = Σ_m P(m|x)·Σ_z P(y|m,z)P(z)。
89
- - **do-演算**:三规则在可观测量间转换 do-表达式(见核心原则数学形式化块)。
90
-
91
- ### 第四步:计算干预效果 / Compute Intervention Effects
92
- 用调整公式算 P(y|do(x)),与观察性 P(y|x) 对比衡量混淆偏差:
93
- - 后门调整:P(y|do(x)) = Σ_z P(y|x,z)·P(z)——对 Z 所有取值加权平均。
94
- - 混淆偏差:|P(y|do(x)) - P(y|x)|——偏差越大混淆越严重。
95
- - 平均处理效应:ATE = E[Y|do(X=1)] - E[Y|do(X=0)] = E[Y(1)] - E[Y(0)]。
96
- **关键**:P(y|do(x)) 与 P(y|x) 是否显著不同?不同则观察性分析有混淆偏差。
97
-
98
- ### 第五步:反事实分析 / Counterfactual Analysis
99
- 个体层面回顾性推理:若 X 是 x₁ 而非 x₀,Y 会怎样?
100
- - **SCM**:Y = f(X, Z, U),U 为外生变量。
101
- - **反事实计算**:给定观测 (x₀,y₀,z₀),反事实 Y_{x₁} = f(x₁, z₀, u₀)。
102
- - **个体因果效应**:Y_{x₁} - Y_{x₀}——需结构方程。
103
- **关键**:反事实依赖结构方程具体形式,对模型假设极敏感。
104
-
105
- ### 第六步:实验设计验证 / Experimental Design
106
- - **RCT(黄金标准)**:随机化切断所有指向 X 的箭头,处理组与对照组在所有变量上期望相等;ATE = E[Y|do(X=1)] - E[Y|do(X=0)]。
107
- - **自然实验**:利用自然发生的准随机事件(地震、政策变更)。
108
- - **工具变量 IV**:V→X 且 V 到 Y 无直接路径、V 与 Y 无共同原因——用 V 创造的 X 变异估计因果效应。
109
- - **双重差分 DD**:(Y₁^后-Y₁^前) - (Y₀^后-Y₀^前)。
110
-
111
- ### 第七步:敏感性分析 / Sensitivity Analysis
112
- 量化结论对未观测混淆的脆弱性:
113
- - **Rosenbaum Γ**:对混淆强度 Γ,算结论可能翻转的最大 p-value——Γ 越大越脆弱。
114
- - **E-value**:使效应估计归零所需的最小混淆强度——越大越稳健。
115
- **关键**:未观测混淆 U 必须多强才能推翻结论?
116
-
117
- ## 常见错误 / Common Errors
118
-
119
- | 错误 / Error | 批评 / Critique | 正确做法 / Correct Approach |
120
- |---|---|---|
121
- | 从相关直接推断因果 | P(y\|x)≠P(y\|do(x));相关可能由混淆创造 | 画 DAG 识别混淆,用后门调整算 P(y\|do(x)) |
122
- | 忽略混淆变量 | 不调整时 \|P(y\|do(x))-P(y\|x)\|=混淆偏差 | 找 X、Y 所有共同祖先,调整可观测混淆 |
123
- | 混淆 do(x) 与条件化 P(y\|x) | do(x) 切断指向 X 的箭头,条件化不切断 | 明确区分干预(强制设定)与观察(看到时) |
124
- | 忽略中介效应 | X→M→Y 总效应=直接+间接 | 中介分析拆分直接/间接效应,前门准则可用 |
125
- | 过度依赖单一 DAG | DAG 错则结论全错,不同 DAG 可能给相反结论 | 检验 DAG 合理性,比较多个备选 DAG |
126
- | 忽略敏感性分析 | 未观测混淆可能推翻结论 | 用 Rosenbaum Γ 或 E-value 量化脆弱性 |
127
- | 精确因果图搜索不可算 | DAG 空间超指数、NP-hard、不可微 | 连续松弛(NOTEARS)/启发式近似,过 GPU 八维门 |
128
-
129
- ## 操作规程 / Operating Procedure
130
-
131
- 当本 skill 被触发时,输出必须包含:
132
-
133
- 1. **[DAG]**:所有变量的有向无环图,标注每条箭头的假设依据。
134
- 2. **[混淆变量]**:列出 X、Y 的所有共同祖先,标注可观测/不可观测。
135
- 3. **[识别策略]**:后门/前门/do-演算,说明选择理由。
136
- 4. **[干预效果]**:P(y|do(x))=[值],用调整公式计算并与 P(y|x) 对比。
137
- 5. **[反事实]**:对关键个体/子群反事实推理,说明所需结构方程。
138
- 6. **[验证方法]**:RCT/自然实验/IV/DD,如何验证因果结论。
139
- 7. **[敏感性]**:Rosenbaum Γ 或 E-value,量化对未观测混淆的脆弱性。
140
- 8. **[GPU 可行性]**(若用于可解释性/OOD/DGP 建模的大规模估计):因果发现/估计方法过八维门,标注友好/可改造/不友好 + 改造建议。
141
-
142
- **输出不得只给分析而无结论。**
143
-
144
- ## 与其他 skill 的关系 / Relations to Other Skills
145
-
146
- - **概率与统计**:统计是因果的基础但不充分——P(y|x) 是关联,P(y|do(x)) 是因果效应;因果需额外假设。
147
- - **建模思想**:因果 DAG 是结构模型——编码变量间因果机制假设,是建模的因果版本。
148
- - **逻辑演绎**:从 DAG 假设出发,通过 do-演算三规则演绎因果结论。
149
- - **信息论思想**:混淆变量制造虚假信号,因果推断从噪声中提取真实因果信号。
150
- - **博弈思想**:策略互动中参与者的选择构成因果干预,均衡分析需因果推理。
151
- - **现代数学激活**:`../../references/books/optimization-ml.md`(干预估计/regression、双重 ML)、`../../references/books/matrix-analysis.md`(条件独立检验、精度阵低秩近似)。
@@ -1,136 +0,0 @@
1
- # Mathematical Sources and Classic Texts
2
-
3
- ## Wright's Path Analysis and DAGs (1921)
4
-
5
- > Path coefficient p_{ij}: a standardized measure of the direct causal effect of variable i on variable j.
6
- > The total effect along each path from i to j = the product of the coefficients along that path.
7
-
8
- **Significance**: Causal structure can be represented with directed graphs, and causal effects can be computed along paths on the graph — this is the origin of causal DAGs.
9
-
10
- **Mathematical background**: Sewall Wright (1921) invented path diagrams while studying genetics, to decompose the hereditary and environmental components of traits. Path analysis is essentially the graphical representation of structural equation models (SEM): each variable's value is determined by its direct causes and an exogenous error term, Y = Σ β_{ij}·X_j + ε_j. Wright's path tracing rule allows one to compute the total association between variables along DAG paths: r_{XY} = Σ(product of path coefficients). This approach laid the foundation for Pearl's DAG framework.
11
-
12
- **Key formula**: Wright's tracing rule: total association r_{ij} = Σ(product of path coefficients along each open path from i to j). An open path has no loops and no colliders (nodes receiving two arrows). Colliders block paths by default, but conditioning on a collider opens the path — the origin of "collider bias."
13
-
14
- ## Fisher's Randomized Experiments (1935)
15
-
16
- > Randomization does not ignore causation; it makes causal inference possible.
17
- > Random assignment severs all causal arrows pointing into the treatment variable.
18
-
19
- **Significance**: The credibility of scientific experiments comes not from "precise control" but from "random assignment" — randomization is the gold standard for causal inference.
20
-
21
- **Mathematical background**: R.A. Fisher, in *The Design of Experiments* (1935), introduced the principle of randomization. The core argument: if treatment T is randomly assigned to individuals, then T is independent of any confounder Z (P(Z|do(T)) = P(Z)), so P(Y|do(T)) = P(Y|T). Randomization eliminates all back-door paths without needing to identify specific confounders. Fisher also proposed exact tests under the null hypothesis (permutation test): under the assumption that T has no effect, the distribution of Y values is the same across all possible assignments, and the p-value = "the probability of observing the current or a more extreme assignment."
22
-
23
- **Fisher's exact test and permutation inference**: Fisher's lady tasting tea experiment is the classic case of randomized inference. A lady claimed she could distinguish whether milk was poured before or after the tea. Fisher designed an experiment with 8 cups (4 with milk first, 4 with tea first), presented in random order. Under the null hypothesis (the lady has no discriminatory ability), the probability of correctly identifying all 4 milk-first cups = 1/C(8,4) = 1/70 ≈ 0.014. This p-value does not rely on any distributional assumption — it is based entirely on the randomization assignment, and is the origin of the permutation test.
24
-
25
- ## Wright's Instrumental Variables (1928)
26
-
27
- > An instrumental variable V satisfies: (1) V → X (affects treatment), (2) V has no direct path to Y, (3) V shares no common cause with Y.
28
- > IV estimator: β_{IV} = Cov(Y,V)/Cov(X,V).
29
-
30
- **Significance**: When confounders are unobserved, instrumental variables exploit "exogenous variation" to estimate causal effects — the variation in X created by the IV is unaffected by confounding.
31
-
32
- **Mathematical background**: Philip Sewall Wright (1928) first proposed the instrumental variable method when estimating the demand elasticity of flaxseed. He needed to estimate the causal effect of price on quantity demanded, but price and quantity demanded exhibit bidirectional causality (confounding). Wright introduced a variable that only affects supply (and thus price) but does not directly affect demand as an instrument. The logic of IV estimation: Cov(Y,V) = β_{causal}·Cov(X,V) + Cov(confounder, U·V), but since V is independent of the confounder, Cov(confounder, U·V) = 0, so β_{causal} = Cov(Y,V)/Cov(X,V). When the IV is weak (small Cov(X,V)), the variance of the IV estimator inflates, and one must beware of weak instrument problems.
33
-
34
- **Classic IV cases**:
35
-
36
- - **Angrist & Krueger (1991)**: used birth quarter as an instrumental variable for years of education — those born early in the year were compelled to attend more school due to school-entry age regulations. The IV-estimated return to education was approximately 7%, higher than the OLS estimate of 5% (OLS biased downward by ability confounding).
37
- - **Two-Stage Least Squares (2SLS)**: first stage X̂ = π₀ + π₁·V (predict X using the IV); second stage Y = β₀ + β₁·X̂ (estimate the causal effect using predicted values). When the IV is strong (F-statistic > 10), 2SLS is reliable; when the IV is weak, 2SLS is biased toward OLS and confidence intervals inflate.
38
-
39
- ## Lewis's Counterfactual Semantics (1973)
40
-
41
- > "If A had occurred (which it didn't), would C have happened?" — In the possible world where A holds, does C hold?
42
-
43
- **Significance**: Causal claims inherently involve counterfactuals — "A caused C" means "if A hadn't occurred, C wouldn't have." Counterfactual reasoning requires comparing different possible worlds.
44
-
45
- **Mathematical background**: David Lewis (1973), in *Counterfactuals*, proposed possible-world semantics to analyze counterfactual conditionals. Core concept: similarity ordering — among the possible worlds where A holds, the one closest to the actual world determines the truth value of the counterfactual. Lewis's VC (Variably Strict Conditional) system: A □→ C is true if C holds in all closest A-worlds. This philosophical framework provided the semantic foundation for Pearl's counterfactual computation in structural causal models — the SCM counterfactual Y_x(u) is the value of Y for individual u in the possible world where X is set to x.
46
-
47
- ## Rubin's Potential Outcomes Framework (1974)
48
-
49
- > For individual i: Y_i(1) is the potential outcome under treatment, Y_i(0) is the potential outcome under control.
50
- > Individual causal effect: τ_i = Y_i(1) - Y_i(0) (never simultaneously observable).
51
- > Average Treatment Effect: ATE = E[Y(1) - Y(0)].
52
-
53
- **Significance**: The causal effect is the difference between two potential outcomes — but only one can be observed per individual, which is the "fundamental problem of causal inference."
54
-
55
- **Mathematical background**: Donald Rubin (1974) extended Neyman's (1923) randomization inference framework from agricultural experiments into a general potential outcomes model (the Neyman-Rubin causal model). Key assumption SUTVA (Stable Unit Treatment Value Assumption): (1) individual i's potential outcomes are unaffected by others' treatment assignments, (2) the treatment has a single version (no variations). Under randomization, an unbiased estimator of the ATE is τ̂ = Ȳ_1 - Ȳ_0. Rubin's framework is equivalent to Pearl's: the potential outcomes model provides implicit structural equations in the SCM, and the DAG provides explicit causal assumptions of the potential outcomes model.
56
-
57
- ## Pearl's Causal Hierarchy and Do-Calculus (2000)
58
-
59
- > Causal hierarchy:
60
- > Level 1: P(y|x) — Association / Seeing
61
- > Level 2: P(y|do(x)) — Intervention / Doing
62
- > Level 3: P(y_x|x',y') — Counterfactual / Imagining
63
- >
64
- > The three rules of do-calculus allow interventional expressions to be converted into observable quantities.
65
-
66
- **Significance**: Causation is not a strengthened version of correlation — "do(x)" and "observe x" are mathematically distinct. Do-calculus provides a complete logical system for computing causal effects from observational data.
67
-
68
- **Mathematical background**: Judea Pearl, in *Causality* (2000), established the mathematical framework for causal inference. Core contributions: (1) the causal hierarchy classifies reasoning capabilities from association to intervention to counterfactual in three levels, each requiring stronger modeling assumptions; (2) the three rules of do-calculus provide a complete set of rules for converting do-expressions into do-free observational expressions; (3) Pearl proved the completeness of do-calculus — if a do-expression can be converted into an observational expression, the three rules of do-calculus will find that conversion. The back-door criterion and front-door criterion are the most important special cases of do-calculus.
69
-
70
- ## Card & Krueger Difference-in-Differences (1994)
71
-
72
- > DD = (Y₁^{post} - Y₁^{pre}) - (Y₀^{post} - Y₀^{pre})
73
- > The pre-post change in the treatment group minus the pre-post change in the control group = the pure causal effect.
74
-
75
- **Significance**: When RCTs are impossible, difference-in-differences estimates causal effects by comparing pre-post changes between treatment and control groups — provided the parallel trends assumption holds.
76
-
77
- **Mathematical background**: David Card and Alan Krueger (1994), in studying the effect of minimum wage on employment, compared changes in fast-food employment between New Jersey (which raised the minimum wage) and Pennsylvania (which did not). The key assumption of DD: in the absence of intervention, the trends of the treatment and control groups are the same (parallel trends assumption). Mathematically, the DD estimator is τ̂_{DD} = (Ȳ_{NJ,post} - Ȳ_{NJ,pre}) - (Ȳ_{PA,post} - Ȳ_{PA,pre}). When parallel trends hold, τ̂_{DD} = ATE. Parallel trends can be partially tested by comparing the pre-intervention time trends of the two groups.
78
-
79
- ## Mediation Analysis: Direct and Indirect Effects
80
-
81
- > X → M → Y: indirect effect = the effect of X on Y through M
82
- > X → Y: direct effect = the direct effect of X on Y not through M
83
- > Total effect = direct effect + indirect effect
84
-
85
- **Significance**: Causal effects propagate along different paths — decomposing direct and indirect effects helps understand causal mechanisms.
86
-
87
- **Mathematical background**: Baron & Kenny (1986) proposed the classical method of mediation analysis (stepwise regression), but this method has serious flaws: it relies on linearity assumptions, ignores interaction effects, and cannot handle confounding. Pearl (2001) proposed the definitions for causal mediation analysis: natural direct effect NDE = E[Y_{x,M_{x'}}] - E[Y_{x',M_{x'}}] (the effect of changing X from x' to x while holding M at its natural value under x'); natural indirect effect NIE = E[Y_{x',M_x}] - E[Y_{x',M_{x'}}] (the effect of changing M from its natural value under x' to its natural value under x, while holding X at x'). Total effect = NDE + NIE. This definition does not rely on linearity assumptions.
88
-
89
- ## Rosenbaum's Sensitivity Analysis (2002)
90
-
91
- > Given confounding strength Γ: maximum odds ratio P(U=1|T=1)/P(U=1|T=0) ≤ Γ.
92
- > Compute: the maximum p-value at which the causal conclusion could be overturned under Γ.
93
-
94
- **Significance**: Causal conclusions must be assessed for robustness — if an unobserved confounder of strength Γ can overturn the conclusion, it is fragile.
95
-
96
- **Mathematical background**: Paul Rosenbaum, in *Observational Studies* (2002), systematized sensitivity analysis methods. Core idea: under randomization Γ=1 (treatment completely independent of confounders), Γ>1 indicates the possibility of unobserved confounding. For each Γ, compute: the minimum p-value for the treatment effect under the strongest possible confounding. If the p-value already exceeds the significance threshold at Γ=2, the conclusion is fragile to even weak confounding; if the p-value remains significant at Γ=5, the conclusion is highly robust. The E-value (VanderWeele & Ding, 2017) is a related concept: the minimum confounding strength required to nullify the effect estimate, E-value = ATE + √(ATE² + ATE).
97
-
98
- ## Pearl's Structural Causal Models (SCM)
99
-
100
- > SCM = ⟨U, V, F, P(U)⟩
101
- > U = exogenous variables (unobserved individual characteristics), V = endogenous variables (observed), F = structural equations {f_V}, P(U) = exogenous distribution
102
- >
103
- > Structural equation: V_i = f_i(PA_i, U_i), PA_i = direct causes (parent nodes) of V_i
104
-
105
- **Significance**: Structural Causal Models provide the complete mathematical framework for causal inference — they simultaneously encode causal assumptions (DAG), interventions (do-calculus), and counterfactuals (structural equations).
106
-
107
- **Mathematical background**: Pearl's SCM framework unifies the three levels of causal inference. Core mathematical objects: (1) the DAG encodes causal assumptions — the arrow PA_i → V_i indicates that PA_i is a direct cause of V_i; (2) structural equations V_i = f_i(PA_i, U_i) encode causal mechanisms — f_i is a causal function, not a statistical regression; (3) the mathematical operation of intervention do(X=x): replace the structural equation for X with X=x, keeping all other equations unchanged; (4) counterfactual computation Y_x(u): in the modified model (X=x), given exogenous variables U=u, compute the value of Y. Key property of SCM: from an SCM, all Level 1-3 quantities can be derived; conversely, Level 1 data alone cannot uniquely determine the SCM.
108
-
109
- ## The Fundamental Problem of Causal Inference
110
-
111
- > For individual i: τ_i = Y_i(1) - Y_i(0)
112
- > We can never simultaneously observe Y_i(1) and Y_i(0) — we can only see one of them.
113
-
114
- **Significance**: Individual causal effects can never be directly observed — this is the fundamental problem of causal inference. All causal inference methods are essentially attempting to infer complete effects from partial information.
115
-
116
- **Mathematical background**: Holland (1986) explicitly articulated this fundamental problem. Each individual i has two potential outcomes Y_i(treated) and Y_i(control), but the real world reveals only one. All causal inference strategies are essentially ways of circumventing this limitation: (1) randomization — replace individual effects with group means; (2) before-after comparison — approximate the control state using the individual's prior state (assuming no time trends); (3) regression adjustment — approximate individuals by matching on observable characteristics; (4) counterfactual modeling — predict unobserved potential outcomes using structural equations. Each strategy has its assumptions; violating them invalidates the conclusions.
117
-
118
- ## Simpson's Paradox and Causal Structure
119
-
120
- > The same data yields opposite conclusions under different groupings:
121
- > Overall: the treatment group has a higher recovery rate; stratified (by disease severity): the treatment group has a lower recovery rate.
122
-
123
- **Significance**: The direction of statistical association depends on the level of analysis — Simpson's paradox reveals that pure statistical reasoning cannot determine "which grouping is correct"; causal assumptions are required.
124
-
125
- **Mathematical background**: The essence of Simpson's paradox is confounding. Classic case: in a drug trial, mild patients are mostly assigned to the treatment group (high recovery rate), while severe patients are mostly assigned to the control group (low recovery rate). Overall, the treatment group shows a higher recovery rate (because it contains mostly mild patients), but after stratification by severity, the treatment group shows a lower recovery rate (the drug is actually harmful). Pearl's causal explanation: if disease severity Z is a confounder (Z→T and Z→Y), then P(Y|T=1) > P(Y|T=0) is a spurious association; the correct causal effect P(Y|do(T=1)) < P(Y|do(T=0)) requires back-door adjustment P(Y|do(T)) = Σ_z P(Y|T,z)·P(z). The causal DAG determines "whether to stratify by Z or compute overall" — without a causal model, statistical methods alone cannot provide an answer.
126
-
127
- ## d-Separation and Conditional Independence
128
-
129
- > In DAG G, path p is d-separated by Z if p contains:
130
- > (1) a chain A→B→C with B∈Z, or
131
- > (2) a fork A←B→C with B∈Z, or
132
- > (3) a collider A→B←C with B∉Z (and descendants of B ∉Z).
133
-
134
- **Significance**: d-separation is the conditional independence encoded by the DAG — if X and Y are d-separated by Z, then X ⊥ Y | Z holds in all distributions generated by G.
135
-
136
- **Mathematical background**: d-separation (directed separation) was proposed by Pearl (1988) to connect the causal graph structure with the independence properties of probability distributions. The three blocking rules correspond to three types of paths: chains (causal transmission paths), forks (confounding paths), and colliders (selection bias paths). Key properties of d-separation: (1) if X and Y are d-separated by Z, then X ⊥ Y | Z should be observed in the data — if X and Y remain correlated given Z, the DAG may be incorrect; (2) d-separation is an implication of the DAG — one need not know specific parameter values, as independence can be inferred from graph structure alone; (3) d-separation is foundational for causal reasoning — back-door paths are precisely non-causal paths not d-separated by the empty set.
@@ -1,167 +0,0 @@
1
- # 数学出处与经典文献 / Mathematical Sources and Classic Texts
2
-
3
- ## Wright 路径分析与 DAG / Wright's Path Analysis and DAGs (1921)
4
-
5
- > 路径系数 p_{ij}:变量 i 对变量 j 的直接因果效应的标准化度量。
6
- > 每条从 i 到 j 的路径的总效应 = 路径上各系数的乘积。
7
-
8
- **含义**:因果结构可以用有向图表示,因果效应可以在图上沿路径计算——这是因果 DAG 的起源。
9
-
10
- **数学背景**:Sewall Wright (1921) 在研究遗传学时发明路径图(path diagrams),用于分解性状的遗传与环境成分。路径分析的本质是结构方程模型(SEM)的图表示:每个变量的值由其直接原因和外生误差项决定,Y = Σ β_{ij}·X_j + ε_j。Wright 的路径追踪规则允许沿 DAG 路径计算变量间的总关联:r_{XY} = Σ(路径上系数乘积)。这一方法为 Pearl 的 DAG 框架奠定了基础。
11
-
12
- **Significance**: Causal structure can be represented with directed graphs, and causal effects can be computed along paths on the graph — this is the origin of causal DAGs. Wright invented path diagrams in genetics to decompose hereditary and environmental components of traits. Path analysis is essentially the graphical representation of structural equation models (SEM).
13
-
14
- **关键公式**:路径追踪规则(Wright's tracing rule):变量 i 与 j 间的总关联 r_{ij} = Σ(沿 i→j 的每条开放路径上路径系数乘积)。开放路径是指不经过同一变量两次(无回路)且不含"对撞"(collider)的路径——对撞是两条箭头同时指向的节点。对撞节点默认阻断路径,但若对撞被条件化,则路径重新开放——这就是"对撞偏差"(collider bias)的来源。
15
-
16
- **Key formula**: Wright's tracing rule: total association r_{ij} = Σ(product of path coefficients along each open path from i to j). An open path has no loops and no colliders (nodes receiving two arrows). Colliders block paths by default, but conditioning on a collider opens the path — the origin of "collider bias."
17
-
18
- ## Fisher 随机化实验 / Fisher's Randomized Experiments (1935)
19
-
20
- > 随机化不是忽视因果,而是使因果推断成为可能。
21
- > 随机分配切断所有指向处理变量的因果箭头。
22
-
23
- **含义**:科学实验的可信度不来自"精密控制",而来自"随机分配"——随机化是因果推断的黄金标准。
24
-
25
- **数学背景**:R.A. Fisher 在《The Design of Experiments》(1935) 中提出随机化原则。核心论证:若处理 T 随机分配给个体,则 T 与任何混淆变量 Z 独立(P(Z|do(T)) = P(Z)),因此 P(Y|do(T)) = P(Y|T)。随机化消除了所有后门路径,无需识别具体混淆变量。Fisher 还提出零假设下的精确检验(permutation test):在 T 无效应假设下,所有可能分配的 Y 值分布相同,p-value = "观察到当前或更极端分配的概率"。
26
-
27
- **Significance**: The credibility of scientific experiments comes not from "precise control" but from "random assignment" — randomization is the gold standard for causal inference. Fisher showed that if treatment T is randomly assigned, T is independent of any confounder Z, so P(Y|do(T)) = P(Y|T). Randomization eliminates all back-door paths without needing to identify specific confounders.
28
-
29
- **Fisher 精确检验与置换推断**:Fisher 的 lady tasting tea 实验是随机化推断的经典案例。一位女士声称能分辨茶是先加奶还是后加奶。Fisher 设计了 8 杯茶(4 杯先加奶、4 杯后加奶),随机顺序呈现。在"女士无辨别能力"(零假设)下,正确猜中 4 杯先加奶的概率 = 1/C(8,4) = 1/70 ≈ 0.014。这一 p-value 不依赖任何分布假设——它完全基于随机化分配,是置换检验(permutation test)的起源。
30
-
31
- ## Wright 工具变量 / Wright's Instrumental Variables (1928)
32
-
33
- > 工具变量 V 满足:(1) V → X(影响处理),(2) V 与 Y 无直接路径,(3) V 与 Y 无共同原因。
34
- > IV 估计量:β_{IV} = Cov(Y,V)/Cov(X,V)。
35
-
36
- **含义**:当混淆变量不可观测时,工具变量可以利用"外生变异"来估计因果效应——IV 创造的 X 的变异不受混淆影响。
37
-
38
- **数学背景**:Philip Sewall Wright (1928) 在估计亚麻籽需求弹性时首次提出工具变量方法。他需要估计价格对需求量的因果效应,但价格与需求量之间存在双向因果关系(混淆)。Wright 引入一个只影响供给(从而影响价格)但不直接影响需求量的变量作为工具。IV 估计的逻辑:Cov(Y,V) = β_{因果}·Cov(X,V) + Cov(混淆,U·V),但 V 与混淆独立所以 Cov(混淆,U·V)=0,于是 β_{因果} = Cov(Y,V)/Cov(X,V)。当 IV 弱(Cov(X,V) 小),IV 估计的方差膨胀,需警惕弱工具变量问题。
39
-
40
- **Significance**: When confounders are unobserved, instrumental variables exploit "exogenous variation" to estimate causal effects — the variation in X created by IV is unaffected by confounding. Wright first proposed IV estimation for flaxseed demand elasticity. The logic: since V is independent of confounders, β_{causal} = Cov(Y,V)/Cov(X,V). Weak IV (small Cov(X,V)) inflates variance — beware of weak instrument problems.
41
-
42
- **经典 IV 案例**:
43
-
44
- - **Angrist & Krueger (1991)**:用出生季度作为教育年数的工具变量——出生在年初的人因入学年龄规定而被迫多上一年学。IV 估计的教育回报率约 7%,高于 OLS 的 5%(OLS 受能力混淆向下偏)。
45
- - **两阶段最小二乘 (2SLS)**:第一阶段 X̂ = π₀ + π₁·V(用 IV 预测 X);第二阶段 Y = β₀ + β₁·X̂(用预测值估计因果效应)。当 IV 强时(F-statistic > 10),2SLS 可靠;当 IV 弱时,2SLS 偏向 OLS 且置信区间膨胀。
46
-
47
- **Classic IV cases**: Angrist & Krueger (1991) used birth quarter as IV for education years — those born early in the year were forced to attend more school. IV-estimated education return ~7% vs OLS ~5% (OLS biased down by ability confounding). 2SLS: first stage X̂ = π₀ + π₁·V, second stage Y = β₀ + β₁·X̂. Reliable when F > 10 (strong IV); biased toward OLS when IV is weak.
48
-
49
- ## Lewis 反事实语义 / Lewis's Counterfactual Semantics (1973)
50
-
51
- > "如果 A 发生了(实际上没有),C 会怎样?" ——在 A 成立的可能世界中,C 是否成立?
52
- > Counterfactual: "If A had occurred (which it didn't), would C have happened?" — In the possible world where A holds, does C hold?
53
-
54
- **含义**:因果陈述本质上涉及反事实——"A 导致 C"意味着"如果 A 没发生,C 就不会发生"。反事实推理需要比较不同的可能世界。
55
-
56
- **数学背景**:David Lewis (1973) 在《Counterfactuals》中提出可能世界语义来分析反事实条件句。核心概念:相似性 ordering — 在 A 成立的可能世界中,最接近现实世界的那个决定了反事实的真值。Lewis 的 VC (Variably Strict Conditional) 系统:A □→ C 为真,若在所有最接近的 A-世界中 C 成立。这一哲学框架为 Pearl 的结构因果模型中的反事实计算提供了语义基础——SCM 的反事实 Y_x(u) 就是在"设定 X=x"的可能世界中个体 u 的 Y 值。
57
-
58
- **Significance**: Causal claims inherently involve counterfactuals — "A caused C" means "if A hadn't occurred, C wouldn't have." Counterfactual reasoning requires comparing different possible worlds. Lewis proposed possible-world semantics: the closest A-world to reality determines the truth of the counterfactual. This philosophical framework provided the semantic basis for Pearl's SCM counterfactuals — Y_x(u) is the value of Y for individual u in the world where X is set to x.
59
-
60
- ## Rubin 潜在结果框架 / Rubin's Potential Outcomes Framework (1974)
61
-
62
- > 对于个体 i:Y_i(1) 为处理下的潜在结果,Y_i(0) 为对照下的潜在结果。
63
- > 个体因果效应:τ_i = Y_i(1) - Y_i(0)(永远不可同时观测)。
64
- > 平均处理效应:ATE = E[Y(1) - Y(0)]。
65
-
66
- **含义**:因果效应是两个潜在结果之差——但每个个体只能观测到一个潜在结果,这是因果推断的根本难题("因果推断的根本问题" / fundamental problem of causal inference)。
67
-
68
- **数学背景**:Donald Rubin (1974) 将 Neyman (1923) 在农业实验中的随机化推断框架推广为一般性的潜在结果模型(Neyman-Rubin causal model)。关键假设 SUTVA(Stable Unit Treatment Value Assumption):(1) 个体 i 的潜在结果不受他人处理分配影响,(2) 处理形式唯一(无不同版本)。在随机化下,ATE 的无偏估计为 τ̂ = Ȳ_1 - Ȳ_0。Rubin 的框架与 Pearl 的 DAG 框架是等价的:潜在结果模型是 SCM 中结构方程的隐式表示,DAG 是潜在结果模型中因果假设的显式表示。
69
-
70
- **Significance**: The causal effect is the difference between two potential outcomes — but only one can be observed per individual, the "fundamental problem of causal inference." Rubin extended Neyman's framework into the general potential outcomes model (Neyman-Rubin causal model). SUTVA ensures no interference between units. Under randomization, ATE is unbiasedly estimated by τ̂ = Ȳ_1 - Ȳ_0. Rubin's framework is equivalent to Pearl's: potential outcomes are implicit structural equations, DAGs are explicit causal assumptions.
71
-
72
- ## Pearl 因果层级与 do-演算 / Pearl's Causal Hierarchy and Do-Calculus (2000)
73
-
74
- > 因果层级:
75
- > Level 1:P(y|x) — 关联 / Seeing
76
- > Level 2:P(y|do(x)) — 干预 / Doing
77
- > Level 3:P(y_x|x',y') — 反事实 / Imagining
78
- >
79
- > do-演算三条规则允许将干预表达式转化为可观测量。
80
-
81
- **含义**:因果不是关联的强化版——"do(x)" 与 "observe x" 在数学上截然不同。do-演算提供了从观测数据计算因果效应的完整逻辑系统。
82
-
83
- **数学背景**:Judea Pearl 在《Causality》(2000) 中建立了因果推断的数学框架。核心贡献:(1) 因果层级将推理能力从关联到干预到反事实分为三层,每层需要更强的建模假设;(2) do-演算三条规则给出了将 do-表达式转化为无 do 的可观测量表达式的完整规则集;(3) Pearl 证明了 do-演算的完备性——若一个 do-表达式可以转化为可观测量表达式,do-演算的三条规则必能找到这一转化。后门准则和前门准则是 do-演算的最重要特例。
84
-
85
- **Significance**: Causation is not a strengthened version of correlation — "do(x)" and "observe x" are mathematically distinct. Do-calculus provides a complete logical system for computing causal effects from observational data. Pearl proved completeness: if a do-expression can be converted to an observational expression, the three rules of do-calculus will find it. The back-door and front-door criteria are the most important special cases.
86
-
87
- ## Card & Krueger 双重差分 / Card & Krueger Difference-in-Differences (1994)
88
-
89
- > DD = (Y₁^{post} - Y₁^{pre}) - (Y₀^{post} - Y₀^{pre})
90
- > 处理组的前后变化减去对照组的前后变化 = 纯因果效应。
91
-
92
- **含义**:当 RCT 不可能时,可以利用干预前后处理组与对照组的差异变化来估计因果效应——前提是平行趋势假设成立。
93
-
94
- **数学背景**:David Card 与 Alan Krueger (1994) 在研究最低工资对就业的影响时,比较了新泽西(提高最低工资)与宾夕法尼亚(未提高)的快餐业就业变化。DD 的关键假设:若无干预,处理组与对照组的趋势相同(平行趋势假设)。数学上,DD 估计量 τ̂_{DD} = (Ȳ_{NJ,post} - Ȳ_{NJ,pre}) - (Ȳ_{PA,post} - Ȳ_{PA,pre})。当平行趋势成立时,τ̂_{DD} = ATE。平行趋势可部分检验:比较干预前两个组的时间趋势是否一致。
95
-
96
- **Significance**: When RCT is impossible, difference-in-differences estimates causal effects by comparing pre-post changes between treatment and control groups — provided the parallel trends assumption holds. Card & Krueger studied minimum wage effects on employment by comparing New Jersey (raised minimum wage) with Pennsylvania (did not). The parallel trends assumption can be partially tested by comparing pre-intervention trends.
97
-
98
- ## 中介分析:直接与间接效应 / Mediation Analysis: Direct and Indirect Effects
99
-
100
- > X → M → Y:间接效应 = X 通过 M 对 Y 的影响
101
- > X → Y:直接效应 = X 不通过 M 对 Y 的直接影响
102
- > 总效应 = 直接效应 + 间接效应
103
-
104
- **含义**:因果效应可以沿不同路径传播——拆分直接与间接效应有助于理解因果机制。
105
-
106
- **数学背景**:Baron & Kenny (1986) 提出中介分析的经典方法(逐步回归法),但该方法有严重缺陷:依赖线性假设、忽略交互效应、无法处理混淆。Pearl (2001) 提出因果中介分析的定义:自然直接效应 NDE = E[Y_{x,M_{x'}}] - E[Y_{x',M_{x'}}](将 M 设为 x' 下自然值时,X 从 x' 变为 x 的效应);自然间接效应 NIE = E[Y_{x',M_x}] - E[Y_{x',M_{x'}}](X 保持 x' 时,M 从 x' 下自然值变为 x 下自然值的效应)。总效应 = NDE + NIE。这一定义不依赖线性假设。
107
-
108
- **Significance**: Causal effects propagate along different paths — decomposing direct and indirect effects helps understand causal mechanisms. Baron & Kenny's (1986) classic method has serious flaws. Pearl (2001) defined causal mediation: natural direct effect NDE and natural indirect effect NIE, without requiring linearity. Total effect = NDE + NIE.
109
-
110
- ## Rosenbaum 敏感性分析 / Rosenbaum's Sensitivity Analysis (2002)
111
-
112
- > 给定混淆强度 Γ:最大 odds ratio P(U=1|T=1)/P(U=1|T=0) ≤ Γ。
113
- > 计算:在 Γ 下因果结论可能翻转的最大 p-value。
114
-
115
- **含义**:因果结论必须评估其脆弱性——如果未观测混淆只需强度 Γ 就能推翻结论,则结论不稳健。
116
-
117
- **数学背景**:Paul Rosenbaum 在《Observational Studies》(2002) 中系统化敏感性分析方法。核心思想:在随机化下 Γ=1(处理与混淆完全独立),Γ>1 表示存在未观测混淆的可能。对每个 Γ,计算:在最强可能混淆下,处理效应的最小 p-value。若 Γ=2 时 p-value 已超过显著性阈值,则结论对较弱混淆就脆弱;若 Γ=5 时 p-value 仍显著,则结论非常稳健。E-value (VanderWeele & Ding, 2017) 是相关概念:使效应估计归零所需的最小混淆强度,E-value = ATE + √(ATE² + ATE)。
118
-
119
- **Significance**: Causal conclusions must be assessed for robustness — if an unobserved confounder of strength Γ can overturn the conclusion, it's fragile. Rosenbaum's method: for each Γ, compute the maximum p-value under the strongest possible confounding. If the conclusion remains significant at Γ=5, it's robust. The E-value quantifies the minimum confounding strength needed to nullify the effect estimate.
120
-
121
- ## Pearl 结构因果模型 / Pearl's Structural Causal Models (SCM)
122
-
123
- > SCM = ⟨U, V, F, P(U)⟩
124
- > U = 外生变量(不可观测的个体特征),V = 内生变量(可观测),F = 结构方程 {f_V}, P(U) = 外生分布
125
- >
126
- > 结构方程:V_i = f_i(PA_i, U_i),PA_i = V_i 的直接原因(父母节点)
127
-
128
- **含义**:结构因果模型是因果推断的完整数学框架——它同时编码因果假设(DAG)、干预(do-演算)和反事实(结构方程)。
129
-
130
- **数学背景**:Pearl 的 SCM 框架统一了因果推断的三个层级。核心数学对象:(1) DAG 编码因果假设——箭头 PA_i → V_i 表示 PA_i 是 V_i 的直接原因;(2) 结构方程 V_i = f_i(PA_i, U_i) 编码因果机制——f_i 是因果函数而非统计回归;(3) 干预 do(X=x) 的数学操作:将 X 的结构方程替换为 X=x,保持其他方程不变;(4) 反事实 Y_x(u) 的计算:在修改后的模型(X=x)中,给定外生变量 U=u,计算 Y 的值。SCM 的关键性质:从 SCM 可以推导出所有 Level 1-3 的量;反之,仅从 Level 1 数据无法唯一确定 SCM。
131
-
132
- **Significance**: Structural Causal Models provide the complete mathematical framework for causal inference — they simultaneously encode causal assumptions (DAG), interventions (do-calculus), and counterfactuals (structural equations). The key property: from an SCM, all Level 1-3 quantities can be derived; conversely, Level 1 data alone cannot uniquely determine the SCM.
133
-
134
- ## 因果推断的根本问题 / The Fundamental Problem of Causal Inference
135
-
136
- > 对于个体 i:τ_i = Y_i(1) - Y_i(0)
137
- > 我们永远无法同时观测 Y_i(1) 和 Y_i(0)——只能看到其中一个。
138
-
139
- **含义**:个体因果效应永远不可直接观测——这是因果推断的根本难题。一切因果推断方法本质上都是在试图用部分信息推断完整效应。
140
-
141
- **数学背景**:Holland (1986) 明确阐述了这一根本问题。每个个体 i 有两个潜在结果 Y_i(treated) 和 Y_i(control),但现实世界只呈现其中一个。一切因果推断策略本质上都是绕过这一限制:(1) 随机化——用群体均值替代个体效应;(2) 前后比较——用个体之前状态近似对照状态(假设无时间趋势);(3) 回归调整——用可观测特征匹配近似个体;(4) 反事实建模——用结构方程预测未观测的潜在结果。每种策略都有其假设,违反假设则结论无效。
142
-
143
- **Significance**: Individual causal effects can never be directly observed — this is the fundamental problem of causal inference. All causal inference strategies circumvent this limitation: (1) randomization — replace individual effects with group means; (2) before-after comparison — approximate control state; (3) regression adjustment — match on observables; (4) counterfactual modeling — predict unobserved potential outcomes. Each strategy has assumptions; violating them invalidates conclusions.
144
-
145
- ## Simpson 悖论与因果结构 / Simpson's Paradox and Causal Structure
146
-
147
- > 同一数据在不同分组下给出相反结论:
148
- > 整体:处理组恢复率更高;分组(按病情严重度):处理组恢复率更低。
149
-
150
- **含义**:统计关联的方向取决于分析维度——Simpson 悖论揭示纯统计推理无法确定"哪个分组是正确的",必须依赖因果假设。
151
-
152
- **数学背景**:Simpson 悖论的本质是混淆变量的干扰。经典案例:药物试验中,轻度患者多数被分配到处理组(恢复率高),重度患者多数被分配到对照组(恢复率低)。整体看处理组恢复率更高(因为处理组多为轻度患者),但按病情分组后处理组恢复率更低(药物实际有害)。Pearl 的因果解释:若病情 Z 是混淆变量(Z→T 且 Z→Y),则 P(Y|T=1) > P(Y|T=0) 是虚假关联,正确的因果效应 P(Y|do(T=1)) < P(Y|do(T=0)) 需要后门调整 P(Y|do(T)) = Σ_z P(Y|T,z)·P(z)。因果 DAG 决定了"应该按 Z 分组还是按整体计算"——没有因果模型,统计方法本身无法给出答案。
153
-
154
- **Significance**: The direction of statistical association depends on the level of analysis — Simpson's paradox reveals that pure statistical reasoning cannot determine "which grouping is correct"; causal assumptions are required. Pearl's explanation: if Z is a confounder (Z→T and Z→Y), P(Y|T=1) > P(Y|T=0) is spurious. The correct causal effect P(Y|do(T=1)) < P(Y|do(T=0)) requires back-door adjustment. The causal DAG determines whether to condition on Z or not — without a causal model, statistics alone cannot answer.
155
-
156
- ## d-分离与条件独立性 / d-Separation and Conditional Independence
157
-
158
- > 在 DAG G 中,路径 p 被 Z d-阻断,若 p 包含:
159
- > (1) 一个链 A→B→C 且 B∈Z,或
160
- > (2) 一个叉 A←B→C 且 B∈Z,或
161
- > (3) 一个对撞 A→B←C 且 B∉Z(且 B 的后代∉Z)。
162
-
163
- **含义**:d-分离是 DAG 编码的条件独立性——若 X 与 Y 被 Z d-分离,则 X ⊥ Y | Z 在所有由 G 产生的分布中成立。
164
-
165
- **数学背景**:d-分离(directed separation)是 Pearl (1988) 提出的概念,连接因果图结构与概率分布的独立性。三条阻断规则对应三种路径类型:链(因果传导路径)、叉(混淆路径)、对撞(选择偏差路径)。d-分离的关键性质:(1) 若 X 与 Y 被 Z d-分离,则数据中应观察到 X ⊥ Y | Z——若观察到 X 与 Y 在给定 Z 时仍相关,则 DAG 可能错误;(2) d-分离是 DAG 的蕴涵——不需要知道具体参数值,仅从图结构即可推断独立性;(3) d-分离是因果推理的基础——后门路径就是不被空集 d-阻断的非因果路径。
166
-
167
- **Significance**: d-separation is the conditional independence encoded by the DAG — if X and Y are d-separated by Z, then X ⊥ Y | Z holds in all distributions generated by G. The three blocking rules correspond to: chains (causal transmission), forks (confounding), colliders (selection bias). d-separation is foundational for causal reasoning — back-door paths are exactly non-causal paths not d-separated by the empty set.
@@ -1,124 +0,0 @@
1
- ---
2
- name: discrete-combinatorial
3
- description: |
4
- 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.
5
- ---
6
-
7
- # 🧮 Discrete & Combinatorial
8
-
9
- > "Counting is the oldest mathematical activity — finite objects harbor infinite patterns."
10
- >
11
- > — Combinatorics, Graph Theory, Generating Functions
12
-
13
- ## Core Principle
14
-
15
- **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.**
16
-
17
- > **Mathematical Formalization**
18
- >
19
- > **Pigeonhole Principle**: Place $n$ items into $m < n$ boxes; then some box contains at least 2 items. Generalization: $kn+1$ items into $n$ boxes implies some box contains at least $k+1$. A powerful tool for existence proofs — proves that something must exist without constructing a specific instance.
20
- >
21
- > **Inclusion-Exclusion Principle**: $|A_1\cup\ldots\cup A_n| = \sum|A_i| - \sum|A_i\cap A_j| + \ldots \pm |A_1\cap\ldots\cap A_n|$; complement counting: "does not have property $P$" = total $-$ "has property $P$."
22
- >
23
- > **Generating Functions**: Ordinary generating function (OGF) $A(x)=\sum a_n x^n$ (unordered / combinatorial; coefficient of $A\cdot C$ is $\sum a_i\cdot c_{n-i}$); exponential generating function (EGF) $B(x)=\sum b_n x^n/n!$ (ordered / labeled; coefficient of $B\cdot D$ divided by $n!$ is $\sum (b_i/i!)\cdot(d_{n-i}/(n-i)!)$).
24
- >
25
- > **Polya Enumeration Theorem**: Counting orbits under group action $= (1/|G|)\sum_{g\in G}|\text{Fix}(g)|$ (Burnside's lemma), using the cycle index polynomial to count colorings of equivalence classes where "rotations / reflections are considered identical."
26
- >
27
- > Euler's insight: Reinterpret the "divergent series" $1+2+3+\ldots$ as the generating function for partition counting.
28
-
29
- ## GPU-Friendliness (Cross-Cutting Check)
30
-
31
- Discrete / combinatorial structures are often "beautiful but intractable" — exact counting is frequently #P-complete (chromatic counting, matching counting), exact enumeration is NP-hard (Hamiltonian path, subset sum), making direct GPU execution infeasible. GPU deployment must pass through the eight-dimensional gate in `../../references/gpu-friendly-math.md`, reforming via tensorizable aggregation and sampling approximations:
32
-
33
- - **Friendly**: Adjacency matrix power iteration $A^k$ for path counting (GEMM), batch-parallel dynamic programming tables, bitset-packed counting (popcount), structured-sparse graph traversal.
34
- - **Reformable**: Inclusion-exclusion / recurrences → semiring aggregation ($(min,+)$ / $(max,+)$ / Boolean / tropical semiring) tensorized; exact counting → Monte Carlo / importance sampling estimation; enumeration → branch-and-bound pruning + batch parallelism; discrete choices → Gumbel-Softmax relaxation.
35
- - **Anti-patterns**: Exact full enumeration ($n!$ explosion), serial backtracking search, strongly serial DP (long-range dependencies not parallelizable), unstructured graph random access — "beautiful but intractable"; must approximate or relax.
36
-
37
- Eight-dimensional minimum assessment (formal terms): **Tensorization** — whether finite objects can be encoded as matrices / bitsets / batched tables; **GEMM-mappability** — whether recurrences admit semiring matrix formulation; **Complexity** — identify NP-hard / #P-hard problems and approximation bounds; **Memory and KV-Cache** — check whether enumeration tables, DP tables, and adjacency structures explode; **Low-precision stability** — whether relaxation sampling and semiring operations are numerically robust; **Parallelism and communication** — whether subproblems are independent or admit skewed-scan parallelism; **Sparse structure** — adopt only block / banded / regular-graph sparsity; **Operator fusion** — whether counting, masking, and sampling can be merged into a small number of kernels.
38
-
39
- > Use in conjunction with `../../references/books/abstract-algebra.md` (semirings / finite-field aggregation), `../../references/books/matrix-analysis.md` (adjacency matrices / spectral graphs).
40
-
41
- ## When NOT to Use
42
-
43
- - **Continuous / analytical problems with no discrete structure** — limits, derivatives, and integrals rather than counting finite objects; this is analysis, not combinatorics.
44
- - **An exact closed-form formula directly gives the answer** — combinatorial enumeration is overhead (e.g., $n\cdot(n-1)$ is a direct algebraic computation).
45
- - **Pure probability problems with no combinatorial structure** — continuous distribution parameter estimation, Bayesian updating do not involve counting over finite sets; probability density integration is not a combinatorial problem.
46
-
47
- ## When to Use
48
-
49
- - Need to count the number of configurations (permutations / selections / allocations); the answer is a specific finite number, not 1 or infinity.
50
- - Need to prove existence via the pigeonhole principle ("there must exist an object with a certain property") without constructing an instance.
51
- - Need to discover a recurrence or closed-form formula for an enumeration sequence $\{a_n\}$ (e.g., Catalan numbers $C_n = (2n)!/(n!(n+1)!)$).
52
- - Need to enumerate configurations satisfying constraints — classified by structure, generated by rules, not random listing.
53
- - Need graph / network analysis (connectivity, paths, matchings, colorings, covers) — social networks, scheduling, and planning can be modeled as graph problems.
54
- - Need to solve recurrence relations for closed-form formulas or asymptotic behavior — recurrence → generating function → algebraic solution → coefficient extraction.
55
- - **Design combinatorial schemes for sparse / routing / topological structures** — sparse attention patterns, routing tables / topological sorting, block-structured sparse layouts.
56
-
57
- ## Method
58
-
59
- ### Step 1: Identify the Discrete Structure and Counting Problem
60
- Specify the **counting object** (permutations / combinations / partitions / arrangements), the **goal** (total count / constrained subset / probability), and the **constraints** (mutually exclusive, ordered / unordered, labeled / unlabeled). Classification: permutations $P(n,k)=n!/(n-k)!$; combinations $C(n,k)=n!/(k!(n-k)!)$; partitions $p(n)$ (integer partitions), $B(n)$ (set partitions); arrangements (items into positions).
61
-
62
- ### Step 2: Apply Fundamental Counting Principles
63
- - **Multiplication principle**: $k$ independent choices → $k_1\times k_2\times\ldots\times k_n$.
64
- - **Addition principle**: Mutually exclusive options → $|A\cup B|=|A|+|B|$ ($A\cap B=\emptyset$).
65
- - **Pigeonhole principle**: $n>m$ implies a collision is unavoidable; some box contains at least $\lceil n/m\rceil$; generalization: $kn+1$ items into $n$ boxes implies some box contains at least $k+1$.
66
-
67
- ### Step 3: Use the Inclusion-Exclusion Principle
68
- $|A_1\cup\ldots\cup A_n| = \sum|A_i| - \sum|A_i\cap A_j| + \sum|A_i\cap A_j\cap A_k| - \ldots \pm |A_1\cap\ldots\cap A_n|$. **Complement counting**: "does not have property $P$" = total $-$ "has property $P$"; classic derangement $D(n) = n! - C(n,1)(n-1)! + C(n,2)(n-2)! - \ldots \pm C(n,n)\cdot 0!$. **Sign rule**: the $k$-th level contributes $(-1)^{k+1}\sum|A_{i_1}\cap\ldots\cap A_{i_k}|$ (odd levels positive, even levels negative).
69
-
70
- ### Step 4: Construct Generating Functions
71
- - **OGF**: $A(x)=\sum a_n x^n$, for unordered / combinatorial structures; coefficient of $A(x)\cdot C(x)$ is $\sum a_i\cdot c_{n-i}$ (combining two independent counts).
72
- - **EGF**: $B(x)=\sum b_n x^n/n!$, for ordered / permutation / labeled structures; coefficient of $B(x)\cdot D(x)$ divided by $n!$ is $\sum (b_i/i!)\cdot(d_{n-i}/(n-i)!)$.
73
- - Classics: partitions $P(x)=\sum p(n)x^n = 1/((1-x)(1-x^2)(1-x^3)\ldots)$; Catalan $C(x)=\sum C_n x^n = (1-\sqrt{1-4x})/(2x)$, derived from $C_n=\sum C_i\cdot C_{n-1-i}$ yielding $C(x)=1+x\cdot C(x)^2$.
74
-
75
- ### Step 5: Analyze Graph Structure
76
- Graph $G=(V,E)$, $|V|$ vertices, $|E|$ edges. Core concepts: degree $\deg(v)$, adjacency / incidence matrices; paths / connected components, shortest paths (Dijkstra, Floyd-Warshall); trees have exactly $n-1$ edges, spanning trees (Kruskal / Prim), binary tree counting via $C_n$; planar graphs — Euler's formula $V-E+F=2$, $E\leq 3V-6$; chromatic number $\chi(G)$, four-color theorem $\chi(\text{planar})\leq 4$; matchings (Hall's marriage theorem, Konig's theorem: maximum matching = minimum vertex cover in bipartite graphs); Eulerian circuits (connected and all degrees even), Hamiltonian circuits (NP-complete).
77
-
78
- ### Step 6: Discover Recurrences and Closed-Form Formulas
79
- - **Recurrences**: Catalan $C_n=\sum C_i\cdot C_{n-1-i}$, Fibonacci $F_n=F_{n-1}+F_{n-2}$, derangements $D_n=(n-1)(D_{n-1}+D_{n-2})$.
80
- - **Generating function solution**: Multiply recurrence by $x^n$ and sum → solve for $A(x)$ → extract $a_n$; Fibonacci $F(x)=x/(1-x-x^2)$, partial fractions yield $F_n=(\varphi^n-\psi^n)/\sqrt{5}$ where $\varphi=(1+\sqrt{5})/2$.
81
- - **Direct formulas**: $C(n,k)=n!/(k!(n-k)!)$ (choose $k$ from $n$, unordered); Catalan $C_n=C(2n,n)/(n+1)$ (combinatorial argument via valid parenthesis sequences).
82
-
83
- ### Step 7: Verify and Generalize
84
- Check small cases $n=0,1,2,3$ by manual enumeration and compare with the formula; verify that the formula counts correctly, the recurrence is self-consistent, and boundary conditions are correct (the empty structure counts as 1: $C_0=1$, $F_0=0$, $F_1=1$); generalize to broader parameters or deeper combinatorial interpretations.
85
-
86
- > **Verification is not optional — an unverified counting formula is not trustworthy.** Manual enumeration for $n=3$ compared with the formula is the minimum verification requirement.
87
-
88
- ## Common Errors
89
-
90
- | Error | Critique | Correct Approach |
91
- |---|---|---|
92
- | Undercounting and overcounting | Undercounting: missing constraint interactions; overcounting: same configuration counted multiple times | Identify constraint interactions explicitly; use inclusion-exclusion to correct overcounting, complement to correct undercounting |
93
- | Ignoring constraint interactions | Constraints are not independent; intersections require inclusion-exclusion | Apply inclusion-exclusion: union = sum of individual sets $-$ intersections |
94
- | Confusing permutations with combinations | Permutations count order: $P(n,k)=n!/(n-k)!$; combinations do not: $C(n,k)=n!/(k!(n-k)!)$ | Determine ordered / unordered first, then select the formula |
95
- | Incorrect inclusion-exclusion signs | Odd levels positive, even levels negative; wrong signs bias the result | Strictly follow $(-1)^{k+1}$ for sign assignment |
96
- | Ignoring generating function convergence | Formal power series can ignore convergence, but closed-form extraction requires convergence domain | Distinguish formal operations from analytic operations |
97
- | Confusing labeled / unlabeled | Labeled structures use EGF; unlabeled structures use OGF | Permutations / distributions → EGF; combinations / partitions → OGF |
98
- | Misapplying the pigeonhole principle | Proves existence only, does not construct instances; requires $n>m$ | Confirm $n>m$; the conclusion is "at least one," not "exactly one" |
99
- | Incorrect recurrence boundary conditions | $C_0=1$ not 0; $F_0=0$, $F_1=1$ | Empty structure = 1; check $n=0,1$ boundary conditions |
100
- | GPU intractability | Exact enumeration / counting is #P or NP-hard and explodes | Reform via semiring aggregation / sampling approximation; pass through the GPU eight-dimensional gate |
101
-
102
- ## Operating Procedure
103
-
104
- When this skill is triggered, the output must include:
105
-
106
- 1. **Structure identification**: `[Structure]: [discrete object]` — counting object, constraints, classification.
107
- 2. **Counting type**: `[Counting type]: [permutation / combination / partition / arrangement]` — ordered / unordered, labeled / unlabeled.
108
- 3. **Principle selection**: `[Principle]: [multiplication / addition / pigeonhole / inclusion-exclusion]` — justification for choice.
109
- 4. **Generating function**: `[Generating function]: [formula]` — GF and algebraic properties (if applicable).
110
- 5. **Graph structure**: `[Graph structure]: [properties]` — vertices / edges / connectivity / coloring (if applicable).
111
- 6. **Recurrence / formula**: `[Recurrence / formula]: [content]` — recurrence and closed-form formula.
112
- 7. **Verification**: `[Verification]: [small cases]` — at minimum, manual enumeration for $n=0,1,2,3$ compared with the formula.
113
- 8. **[GPU Feasibility]** (if used for algorithm / operator design) — whether exact counting / enumeration is NP-hard / #P; whether semiring aggregation / tensorization / sampling approximation is viable; pass through the eight-dimensional gate.
114
-
115
- **Output must not consist of analysis alone without conclusions.**
116
-
117
- ## Relations to Other Skills
118
-
119
- - **Induction and Analogy**: Combinatorial patterns are discovered by induction — from the first few terms of $\{a_n\}$, induce a recurrence, then generalize by analogy to broader structures.
120
- - **Algorithmic Thinking**: Combinatorial counting underpins complexity analysis — $n!$, $C(n,k)$ are foundational for algorithm cost estimation.
121
- - **Probability and Statistics**: Combinatorics is the computational foundation of probability — classical probability $P(A)=|A|/|\Omega|$, where both numerator and denominator are combinatorial counts.
122
- - **Transformation Thinking**: Generating functions transform counting into algebra — sequences → power series, recurrences → equations, counting → coefficient extraction.
123
- - **Axiomatic Thinking**: Combinatorial identities require rigorous proof — $C(n,k)=C(n,n-k)$ demands algebraic or combinatorial argument, not intuition alone.
124
- - **Modern Mathematics Activation**: `../../references/books/abstract-algebra.md` (finite fields / semiring aggregation, Burnside counting), `../../references/books/matrix-analysis.md` (adjacency matrices / spectral graphs / transfer matrices).