math-skill 1.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.en-US.md +313 -0
  2. package/README.md +313 -278
  3. package/agents/math-critic.en.md +235 -0
  4. package/agents/math-critic.md +237 -203
  5. package/commands/abstraction.md +11 -34
  6. package/commands/algorithmic-thinking.md +11 -34
  7. package/commands/ask.md +18 -21
  8. package/commands/axiomatization.md +11 -34
  9. package/commands/causal-inference.md +11 -34
  10. package/commands/discrete-combinatorial.md +11 -34
  11. package/commands/game-theory.md +11 -34
  12. package/commands/induction-analogy.md +11 -34
  13. package/commands/information-theory.md +11 -34
  14. package/commands/logic-deduction.md +11 -34
  15. package/commands/modeling.md +11 -37
  16. package/commands/optimization.md +11 -33
  17. package/commands/probability-statistics.md +11 -36
  18. package/commands/symmetry-invariance.md +11 -34
  19. package/commands/topological-thinking.md +11 -33
  20. package/commands/transformation.md +11 -33
  21. package/knowledge-base/overview.en.md +228 -0
  22. package/knowledge-base/overview.md +230 -230
  23. package/package.json +73 -59
  24. package/references/agentic-workflow.en.md +53 -0
  25. package/references/agentic-workflow.md +55 -0
  26. package/references/books/abstract-algebra.md +124 -0
  27. package/references/books/algebraic-geometry-rising-sea.md +171 -0
  28. package/references/books/differential-geometry.md +140 -0
  29. package/references/books/matrix-analysis.md +146 -0
  30. package/references/books/micro-lie-theory.md +116 -0
  31. package/references/books/optimization-ml.md +164 -0
  32. package/references/books/smooth-manifolds.md +105 -0
  33. package/references/gpu-friendly-math.en.md +65 -0
  34. package/references/gpu-friendly-math.md +67 -0
  35. package/references/inspiration.en.md +113 -0
  36. package/{docs → references}/inspiration.md +2 -0
  37. package/skills/abstraction/SKILL.en.md +117 -0
  38. package/skills/abstraction/SKILL.md +121 -264
  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 +138 -371
  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 +151 -213
  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 +151 -374
  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 +131 -286
  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 +123 -318
  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 +152 -310
  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 +140 -242
  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 +135 -280
  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 +136 -0
  66. package/skills/math-research-activator/original-texts.en.md +105 -0
  67. package/skills/{meta-selector → math-research-activator}/original-texts.md +104 -104
  68. package/skills/modeling/SKILL.en.md +135 -0
  69. package/skills/modeling/SKILL.md +139 -318
  70. package/skills/modeling/original-texts.en.md +162 -0
  71. package/skills/optimization/SKILL.en.md +129 -0
  72. package/skills/optimization/SKILL.md +135 -292
  73. package/skills/optimization/original-texts.en.md +167 -0
  74. package/skills/probability-statistics/SKILL.en.md +146 -0
  75. package/skills/probability-statistics/SKILL.md +151 -312
  76. package/skills/probability-statistics/original-texts.en.md +191 -0
  77. package/skills/symmetry-invariance/SKILL.en.md +135 -0
  78. package/skills/symmetry-invariance/SKILL.md +139 -358
  79. package/skills/symmetry-invariance/original-texts.en.md +206 -0
  80. package/skills/topological-thinking/SKILL.en.md +124 -0
  81. package/skills/topological-thinking/SKILL.md +128 -273
  82. package/skills/topological-thinking/original-texts.en.md +134 -0
  83. package/skills/transformation/SKILL.en.md +120 -0
  84. package/skills/transformation/SKILL.md +124 -264
  85. package/skills/transformation/original-texts.en.md +204 -0
  86. package/docs/CLAUDE.md +0 -187
  87. package/skills/meta-selector/SKILL.md +0 -188
@@ -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).