math-skill 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.en-US.md +40 -7
  2. package/README.md +40 -7
  3. package/agents/math-critic.en.md +235 -0
  4. package/agents/math-critic.md +2 -0
  5. package/commands/abstraction.md +1 -3
  6. package/commands/algorithmic-thinking.md +1 -3
  7. package/commands/ask.md +1 -3
  8. package/commands/axiomatization.md +1 -3
  9. package/commands/causal-inference.md +1 -3
  10. package/commands/discrete-combinatorial.md +1 -3
  11. package/commands/game-theory.md +1 -3
  12. package/commands/induction-analogy.md +1 -3
  13. package/commands/information-theory.md +1 -3
  14. package/commands/logic-deduction.md +1 -3
  15. package/commands/modeling.md +1 -3
  16. package/commands/optimization.md +1 -3
  17. package/commands/probability-statistics.md +1 -3
  18. package/commands/symmetry-invariance.md +1 -3
  19. package/commands/topological-thinking.md +1 -3
  20. package/commands/transformation.md +1 -3
  21. package/knowledge-base/overview.en.md +228 -0
  22. package/knowledge-base/overview.md +2 -0
  23. package/package.json +4 -2
  24. package/references/agentic-workflow.en.md +53 -0
  25. package/references/agentic-workflow.md +2 -0
  26. package/references/books/abstract-algebra.md +4 -0
  27. package/references/books/algebraic-geometry-rising-sea.md +4 -0
  28. package/references/books/differential-geometry.md +4 -0
  29. package/references/books/matrix-analysis.md +4 -0
  30. package/references/books/micro-lie-theory.md +4 -0
  31. package/references/books/optimization-ml.md +4 -0
  32. package/references/books/smooth-manifolds.md +4 -0
  33. package/references/gpu-friendly-math.en.md +65 -0
  34. package/references/gpu-friendly-math.md +2 -0
  35. package/references/inspiration.en.md +113 -0
  36. package/references/inspiration.md +2 -0
  37. package/skills/abstraction/SKILL.en.md +117 -0
  38. package/skills/abstraction/SKILL.md +2 -0
  39. package/skills/abstraction/original-texts.en.md +163 -0
  40. package/skills/algorithmic-thinking/SKILL.en.md +132 -0
  41. package/skills/algorithmic-thinking/SKILL.md +2 -0
  42. package/skills/algorithmic-thinking/original-texts.en.md +253 -0
  43. package/skills/axiomatization/SKILL.en.md +144 -0
  44. package/skills/axiomatization/SKILL.md +2 -0
  45. package/skills/axiomatization/original-texts.en.md +154 -0
  46. package/skills/causal-inference/SKILL.en.md +147 -0
  47. package/skills/causal-inference/SKILL.md +2 -0
  48. package/skills/causal-inference/original-texts.en.md +136 -0
  49. package/skills/discrete-combinatorial/SKILL.en.md +124 -0
  50. package/skills/discrete-combinatorial/SKILL.md +2 -0
  51. package/skills/discrete-combinatorial/original-texts.en.md +184 -0
  52. package/skills/game-theory/SKILL.en.md +117 -0
  53. package/skills/game-theory/SKILL.md +2 -0
  54. package/skills/game-theory/original-texts.en.md +131 -0
  55. package/skills/induction-analogy/SKILL.en.md +145 -0
  56. package/skills/induction-analogy/SKILL.md +2 -0
  57. package/skills/induction-analogy/original-texts.en.md +140 -0
  58. package/skills/information-theory/SKILL.en.md +134 -0
  59. package/skills/information-theory/SKILL.md +2 -0
  60. package/skills/information-theory/original-texts.en.md +127 -0
  61. package/skills/logic-deduction/SKILL.en.md +130 -0
  62. package/skills/logic-deduction/SKILL.md +2 -0
  63. package/skills/logic-deduction/original-texts.en.md +160 -0
  64. package/skills/math-research-activator/SKILL.en.md +132 -0
  65. package/skills/math-research-activator/SKILL.md +2 -0
  66. package/skills/math-research-activator/original-texts.en.md +105 -0
  67. package/skills/modeling/SKILL.en.md +135 -0
  68. package/skills/modeling/SKILL.md +2 -0
  69. package/skills/modeling/original-texts.en.md +162 -0
  70. package/skills/optimization/SKILL.en.md +129 -0
  71. package/skills/optimization/SKILL.md +2 -0
  72. package/skills/optimization/original-texts.en.md +167 -0
  73. package/skills/probability-statistics/SKILL.en.md +146 -0
  74. package/skills/probability-statistics/SKILL.md +2 -0
  75. package/skills/probability-statistics/original-texts.en.md +191 -0
  76. package/skills/symmetry-invariance/SKILL.en.md +135 -0
  77. package/skills/symmetry-invariance/SKILL.md +2 -0
  78. package/skills/symmetry-invariance/original-texts.en.md +206 -0
  79. package/skills/topological-thinking/SKILL.en.md +124 -0
  80. package/skills/topological-thinking/SKILL.md +2 -0
  81. package/skills/topological-thinking/original-texts.en.md +134 -0
  82. package/skills/transformation/SKILL.en.md +120 -0
  83. package/skills/transformation/SKILL.md +2 -0
  84. package/skills/transformation/original-texts.en.md +204 -0
@@ -0,0 +1,147 @@
1
+ ---
2
+ name: causal-inference
3
+ description: |
4
+ Trigger when a problem concerns correlation vs. 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.
5
+ ---
6
+
7
+ # 🔗 Causal Inference
8
+
9
+ > "Correlation is not causation — but causation can be sorted out. Key distinction: 'how is Y when we see X' is not the same as 'what if we did X.'"
10
+ >
11
+ > — Causal Inference, Structural Causal Models, Counterfactual Reasoning
12
+
13
+ ## Core Principle
14
+
15
+ **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.**
16
+
17
+ > **Mathematical Formalization**
18
+ >
19
+ > Pearl's Causal Hierarchy:
20
+ > - **Level 1 — Association**: $P(y|x)$ — Seeing
21
+ > - **Level 2 — Intervention**: $P(y|do(x))$ — Doing
22
+ > - **Level 3 — Counterfactual**: $P(y_x|x',y')$ — Imagining
23
+ >
24
+ > **$do(x) \neq$ conditioning on $x$**: $do(x)$ severs all arrows pointing into $X$ (graph surgery), while conditioning on $x$ severs no arrows. Back-door adjustment: $P(y|do(x)) = \sum_z P(y|x,z)P(z)$
25
+ >
26
+ > **Potential Outcomes (Neyman-Rubin)**: $Y(x)$ denotes "the value $Y$ would take under intervention $X=x$"; individual treatment effect $\tau_i = Y_i(1)-Y_i(0)$; average treatment effect ATE $= E[Y(1)]-E[Y(0)] = E[Y|do(X=1)] - E[Y|do(X=0)]$.
27
+ >
28
+ > **Structural Causal Model (SCM)**: $Y := f(X, Z, U)$, where $U$ is exogenous; the DAG together with structural equations determines the counterfactual $Y_x = f(x, Z, U)$.
29
+ >
30
+ > **d-Separation**: A path is blocked by $Z$ $\iff$ a chain/fork middle node $\in Z$, or a collider $X\to C\leftarrow Y$ has $C$ and its descendants $\notin Z$. d-separation $X\perp_G Y|Z$ implies conditional independence; it is the tool for reading off causal assumptions from the graph.
31
+ >
32
+ > **Do-Calculus — Three Rules** (applied on modified graphs using d-separation):
33
+ > - Rule 1 (Insertion/deletion of observations): If $Y \perp Z \mid X$ in the graph with all arrows into $X$ removed, then $P(y|do(x),z) = P(y|do(x))$
34
+ > - Rule 2 (Exchange of intervention and observation): If $Y \perp Z \mid X$ in the graph with all arrows into $X$ removed and all arrows out of $Z$ removed, then $P(y|do(x),do(z)) = P(y|do(x),z)$
35
+ > - Rule 3 (Insertion/deletion of interventions): If $Y \perp Z \mid X$ in the graph with all arrows into $X$ removed and all arrows from $Z$ to $X$ along paths from $Z$ to $X$ removed, then $P(y|do(x),do(z)) = P(y|do(x))$
36
+ >
37
+ > **Causal reasoning requires an explicit causal model; it cannot be derived from data alone. The DAG encodes causal assumptions, and do-calculus transforms interventional expressions into observable quantities.**
38
+ >
39
+ > See `original-texts.md` for detailed mathematical foundations.
40
+
41
+ ## GPU-Friendliness (Cross-Cutting Check)
42
+
43
+ When causal inference is used for **model interpretability / out-of-distribution generalization / data-generating process modeling** at scale, the methods themselves must pass through the eight-dimensional gate in `../../references/gpu-friendly-math.md`:
44
+
45
+ - **Effect estimation / adjustment regression**: Back-door adjustment, IPW, doubly-robust ML — conditional expectations and regression are all batch GEMM, tensorizable, fusible, low-precision viable — **friendly** (see `../../references/books/optimization-ml.md`).
46
+ - **Conditional independence testing**: High-dimensional conditional independence tests involve precision matrix (covariance inverse) inversion $O(p^3)$; can be reformed via **low-rank / diagonal approximation** or iterative solvers — **retrofittable** (see `../../references/books/matrix-analysis.md`).
47
+ - **Exact causal discovery (DAG search)**: DAG space grows super-exponentially with node count; exact score-based search is NP-hard, non-differentiable, serial — a classic "beautiful but intractable" anti-pattern.
48
+ - **Reform approach**: NOTEARS-style **continuous relaxation** (acyclicity constraint $h(W)=\text{tr}(e^{W\circ W})-p=0$) transforms discrete graph search into differentiable optimization; alternatively, MCMC / greedy + scoring as heuristic approximation.
49
+ - **Counterfactual / SCM simulation**: Forward simulation of structural equations is batch-parallelizable; however, individual counterfactuals depend on identifying exogenous $U$ — watch for serial dependencies.
50
+
51
+ Eight-dimensional minimum assessment (formal terms): **Tensorization** — whether samples / interventions / candidate graphs admit batched processing; **GEMM-mappability** — whether adjustment regression and representation learning fall into matrix multiplication; **Complexity** — whether causal discovery avoids super-exponential DAG search; **Memory and KV-Cache** — whether precision matrices, candidate graphs, and intermediate counterfactuals are compressible; **Low-precision stability** — whether IPW weights, covariance inverses, and logits are numerically robust; **Parallelism and communication** — whether multi-environment / multi-intervention estimation is parallelizable; **Sparse structure** — whether the DAG / SCM is structurally sparse; **Operator fusion** — whether scoring, masking, and loss can be fused.
52
+
53
+ > Use in conjunction with `../../references/books/optimization-ml.md` (intervention estimation / regression) and `../../references/books/matrix-analysis.md` (conditional independence / low-rank precision matrices).
54
+
55
+ ## When NOT to Use
56
+
57
+ - **Pure prediction tasks with no causal question** (only $P(y|x)$ is needed, no interest in "why") — association is sufficient; causation is superfluous.
58
+ - **No encodable causal assumptions** (cannot draw a reasonable DAG; causal directions are uncertain) — without explicit assumptions, no causal conclusions can be drawn.
59
+ - **Deterministic systems with no variation** (inputs map strictly uniquely to outputs) — causation is fully described by the mechanism; the probabilistic causal framework is unnecessary.
60
+
61
+ ## When to Use
62
+
63
+ - Need to know the effect of an intervention ("If we do X, what happens to Y?") — requires $P(y|do(x))$, not $P(y|x)$.
64
+ - Need to distinguish causes from confounders (Does X cause Y, or does Z cause both X and Y?) — DAGs identify confounding paths.
65
+ - Need counterfactual reasoning ("What would have happened if we had not done A?") — Level 3 requires structural equations.
66
+ - Need policy / treatment effect evaluation (back-door adjustment, IV, difference-in-differences when RCTs are infeasible).
67
+ - Need mediation analysis (decomposing direct and indirect effects along $X\to M\to Y$).
68
+ - Need to model the data-generating process (DGP) for **model interpretability / out-of-distribution generalization**, transforming predictor associations into actionable causal mechanisms.
69
+
70
+ ## Method
71
+
72
+ ### Step 1: Construct the Causal DAG
73
+ Identify all variables explicitly; draw causal arrows encoding direct-cause assumptions; verify acyclicity. Identify the cause variable $X$ (intervention target), outcome $Y$ (effect), confounders $Z$ (common causes of $X$ and $Y$), and mediators $M$ ($X\to M\to Y$). An arrow $X\to Y$ means "$X$ is a direct cause of $Y$"; the direction encodes a causal assumption. The DAG must be directed and acyclic — cycles indicate uncertain causal direction and require re-modeling. **Key question**: Is there sufficient domain knowledge to encode causal directions? Conclusions depend entirely on DAG correctness.
74
+
75
+ ### Step 2: Identify Confounders
76
+ Confounders simultaneously affect $X$ and $Y$, creating spurious association — without adjustment, effect estimates are biased. **Definition**: $Z$ is a confounder $\iff$ $Z$ is a common cause of $X$ and $Y$ ($Z\to X$ and $Z\to Y$). **DAG identification**: find all common ancestors of $X$ and $Y$. **Back-door paths** $X\leftarrow Z\to Y$ create non-causal associations that must be blocked. **Key question**: Are all confounders observable? If unobserved confounders exist, back-door adjustment is unavailable and front-door criterion or instrumental variables are needed.
77
+
78
+ ### Step 3: Choose Identification Strategy
79
+ Based on confounder observability, select a strategy for computing $P(y|do(x))$ from observational data:
80
+ - **Back-door criterion**: If $\exists S$ blocking all back-door paths from $X$ to $Y$ and $S$ contains no descendants of $X$, then $P(y|do(x)) = \sum_s P(y|x,S=s)\cdot P(S=s)$.
81
+ - **Front-door criterion**: Confounders are unobservable but mediator $M$ is observable, $X\to M$ has no back-door paths, and $M$ blocks all back-door paths from $X$ to $Y$; then $P(y|do(x)) = \sum_m P(m|x)\cdot\sum_z P(y|m,z)P(z)$.
82
+ - **Do-calculus**: Three rules transform do-expressions among observable quantities (see the Mathematical Formalization block in Core Principle).
83
+
84
+ ### Step 4: Compute Intervention Effects
85
+ Use the adjustment formula to compute $P(y|do(x))$ and compare with the observational $P(y|x)$ to quantify confounding bias:
86
+ - Back-door adjustment: $P(y|do(x)) = \sum_z P(y|x,z)\cdot P(z)$ — weighted average over all values of $Z$.
87
+ - Confounding bias: $|P(y|do(x)) - P(y|x)|$ — larger bias indicates more severe confounding.
88
+ - Average treatment effect: ATE $= E[Y|do(X=1)] - E[Y|do(X=0)] = E[Y(1)] - E[Y(0)]$.
89
+
90
+ **Key question**: Are $P(y|do(x))$ and $P(y|x)$ significantly different? If so, observational analysis suffers from confounding bias.
91
+
92
+ ### Step 5: Counterfactual Analysis
93
+ Individual-level retrospective reasoning: If $X$ had been $x_1$ instead of $x_0$, what would $Y$ have been?
94
+ - **SCM**: $Y = f(X, Z, U)$, where $U$ is exogenous.
95
+ - **Counterfactual computation**: Given observation $(x_0,y_0,z_0)$, the counterfactual $Y_{x_1} = f(x_1, z_0, u_0)$.
96
+ - **Individual causal effect**: $Y_{x_1} - Y_{x_0}$ — requires structural equations.
97
+
98
+ **Key point**: Counterfactuals depend on the specific form of the structural equations and are highly sensitive to model assumptions.
99
+
100
+ ### Step 6: Experimental Design
101
+ - **RCT (gold standard)**: Randomization severs all arrows into $X$; treatment and control groups are equal in expectation on all variables; ATE $= E[Y|do(X=1)] - E[Y|do(X=0)]$.
102
+ - **Natural experiments**: Exploit naturally occurring quasi-random events (earthquakes, policy changes).
103
+ - **Instrumental variables (IV)**: $V\to X$ with no direct path from $V$ to $Y$ and no common cause of $V$ and $Y$ — use the variation in $X$ created by $V$ to estimate the causal effect.
104
+ - **Difference-in-differences (DD)**: $(Y_1^{\text{post}}-Y_1^{\text{pre}}) - (Y_0^{\text{post}}-Y_0^{\text{pre}})$.
105
+
106
+ ### Step 7: Sensitivity Analysis
107
+ Quantify the vulnerability of conclusions to unobserved confounding:
108
+ - **Rosenbaum $\Gamma$**: For confounding strength $\Gamma$, compute the maximum $p$-value at which the conclusion could be overturned — larger $\Gamma$ means more vulnerable.
109
+ - **E-value**: The minimum confounding strength required to nullify the effect estimate — larger values indicate greater robustness.
110
+
111
+ **Key question**: How strong must an unobserved confounder $U$ be to overturn the conclusion?
112
+
113
+ ## Common Errors
114
+
115
+ | Error | Critique | Correct Approach |
116
+ |---|---|---|
117
+ | Inferring causation directly from correlation | $P(y\|x)\neq P(y\|do(x))$; correlation may be created by confounding | Draw a DAG to identify confounders; use back-door adjustment to compute $P(y\|do(x))$ |
118
+ | Ignoring confounders | Without adjustment, $\|P(y\|do(x))-P(y\|x)\|$ equals confounding bias | Find all common ancestors of $X$ and $Y$; adjust for observable confounders |
119
+ | Confusing $do(x)$ with conditioning $P(y\|x)$ | $do(x)$ severs arrows into $X$; conditioning does not | Clearly distinguish intervention (forced setting) from observation (passive seeing) |
120
+ | Ignoring mediation effects | $X\to M\to Y$: total effect = direct + indirect | Perform mediation analysis to decompose direct / indirect effects; front-door criterion may apply |
121
+ | Over-reliance on a single DAG | If the DAG is wrong, all conclusions are wrong; different DAGs can yield opposite conclusions | Validate DAG plausibility; compare multiple candidate DAGs |
122
+ | Skipping sensitivity analysis | Unobserved confounders may overturn conclusions | Quantify vulnerability using Rosenbaum $\Gamma$ or E-value |
123
+ | Intractable exact causal graph search | DAG space is super-exponential, NP-hard, non-differentiable | Use continuous relaxation (NOTEARS) / heuristic approximation; pass through the GPU eight-dimensional gate |
124
+
125
+ ## Operating Procedure
126
+
127
+ When this skill is triggered, the output must include:
128
+
129
+ 1. **[DAG]**: Directed acyclic graph of all variables, with justification for each arrow's causal assumption.
130
+ 2. **[Confounders]**: List all common ancestors of $X$ and $Y$; label each as observable / unobservable.
131
+ 3. **[Identification Strategy]**: Back-door / front-door / do-calculus, with justification for the choice.
132
+ 4. **[Intervention Effect]**: $P(y|do(x))$ = [value], computed via the adjustment formula and compared with $P(y|x)$.
133
+ 5. **[Counterfactuals]**: Counterfactual reasoning for key individuals / subgroups, specifying the required structural equations.
134
+ 6. **[Validation Method]**: RCT / natural experiment / IV / DD — how to validate causal conclusions.
135
+ 7. **[Sensitivity]**: Rosenbaum $\Gamma$ or E-value, quantifying vulnerability to unobserved confounding.
136
+ 8. **[GPU Feasibility]** (if used for large-scale estimation in interpretability / OOD / DGP modeling): Causal discovery / estimation method passes through the eight-dimensional gate; label friendly / retrofittable / unfriendly with reform suggestions.
137
+
138
+ **Output must not consist of analysis alone without conclusions.**
139
+
140
+ ## Relations to Other Skills
141
+
142
+ - **Probability and Statistics**: Statistics is the foundation of causation but is insufficient — $P(y|x)$ is association, $P(y|do(x))$ is causal effect; causation requires additional assumptions.
143
+ - **Modeling Thinking**: Causal DAGs are structural models — they encode hypotheses about causal mechanisms among variables; causal modeling is the causal version of modeling.
144
+ - **Logical Deduction**: Starting from DAG assumptions, causal conclusions are deduced through the three rules of do-calculus.
145
+ - **Information Theory Thinking**: Confounders create spurious signals; causal inference extracts true causal signals from noise.
146
+ - **Game Theory Thinking**: Players' choices in strategic interaction constitute causal interventions; equilibrium analysis requires causal reasoning.
147
+ - **Modern Mathematics Activation**: `../../references/books/optimization-ml.md` (intervention estimation / regression, double ML), `../../references/books/matrix-analysis.md` (conditional independence testing, low-rank precision matrix approximation).
@@ -5,6 +5,8 @@ description: |
5
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
6
  ---
7
7
 
8
+ > **语言路由**:若用户消息为英文,请读取并遵循同目录下的 `SKILL.en.md`,按其操作规程以英文输出;中文消息则继续使用本文件。
9
+
8
10
  # 🔗 因果推断思想 / Causal Inference
9
11
 
10
12
  > "相关不等于因果——但因果可以理清。关键区别:'看到X时Y如何'≠'如果做了X会怎样'"
@@ -0,0 +1,136 @@
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.
@@ -0,0 +1,124 @@
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).
@@ -5,6 +5,8 @@ description: |
5
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
6
  ---
7
7
 
8
+ > **语言路由**:若用户消息为英文,请读取并遵循同目录下的 `SKILL.en.md`,按其操作规程以英文输出;中文消息则继续使用本文件。
9
+
8
10
  # 🧮 离散与组合思想 / Discrete & Combinatorial
9
11
 
10
12
  > "计数是最古老的数学活动——有限对象蕴含无限规律。"