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,132 @@
1
+ ---
2
+ name: algorithmic-thinking
3
+ description: |
4
+ Trigger when a problem needs finite-step solving, algorithm design, complexity analysis (time/space), tractability & parallelism assessment (P/NP-hard/undecidable); or termination/correctness proofs; or designing executable algorithms/operators for GPU (assessing complexity order, parallelism, memory access & fusion).
5
+ ---
6
+
7
+ # 🖥️ Algorithmic Thinking
8
+
9
+ > "An algorithm is the automation of thought — turning insight into precisely repeatable steps."
10
+ >
11
+ > — Computability Theory, Algorithm Analysis, Complexity Theory
12
+
13
+ ## Core Principle
14
+
15
+ **Break problems into executable steps, assess cost, judge feasibility. The first principle is not "how to solve" but "whether it is solvable and at what cost" — some problems are inherently hard (NP-complete), some inherently unsolvable (undecidable); knowing these limits is as important as finding solutions.**
16
+
17
+ > **Mathematical Formalization**
18
+ >
19
+ > A Turing machine M: Σ* → Σ* halts within a finite number of steps. Time complexity T(n) = the maximum number of execution steps for an input of length n; space complexity S(n) = the maximum number of cells used. Church–Turing thesis: anything computable is computable by a Turing machine.
20
+ >
21
+ > Three-tier hierarchy: computable (an algorithm exists) → tractable (a polynomial-time algorithm exists) → intractable (only exponential-time or no algorithm). Computable but intractable is practically equivalent to uncomputable — brute force 2^n is worthless for n=100. P vs NP is precisely the boundary between tractable and intractable.
22
+ >
23
+ > Complexity notation: O(f(n)) upper bound, Ω(f(n)) lower bound, Θ(f(n)) tight bound. Common recurrences: T(n)=2T(n/2)+O(n) → O(n log n); T(n)=T(n-1)+O(n) → O(n²); T(n)=T(n/2)+O(1) → O(log n). Complexity classes: O(1) ⊂ O(log n) ⊂ O(n) ⊂ O(n log n) ⊂ O(n^k) ⊂ O(2^n) ⊂ O(n!).
24
+ >
25
+ > Complexity class definitions: P = polynomial-time decidable; NP-hard = at least as hard as every problem in NP; undecidable = no algorithm can decide it. NP-hard response: approximation (with error bounds) or heuristics (with probabilistic guarantees); undecidable response: find a decidable restricted version.
26
+ >
27
+ > Loop invariant: a property that holds before and after every iteration, which together with the termination condition implies output correctness. Hoare logic: {P} S {Q} — precondition P, after statement S, yields postcondition Q.
28
+
29
+ ## GPU-Friendliness (Cross-Cutting Check)
30
+
31
+ Algorithmic thinking is the weapon most directly relevant to GPU — complexity order, parallelism, memory access/communication, and operator fusion directly determine whether an algorithm can run efficiently on GPU. Every algorithm must pass the `../../references/gpu-friendly-math.md` eight-dimension gate:
32
+
33
+ - **Complexity order**: Sub-quadratic O(n log n)/O(n) is friendly (fully utilizes parallel cores); O(n²) is borderline (GEMM is an exception, salvageable by Tensor Cores); O(2^n)/O(n!) is an anti-pattern.
34
+ - **Parallelism and communication**: Divide-and-conquer / data parallelism is friendly (sub-problems are independent, batchable); dependency chains in dynamic programming and serial search in backtracking require adaptation (chunking / skew scanning).
35
+ - **Memory and KV-Cache / Parallelism and communication**: Coalesced access is friendly; butterfly reductions and prefix scans have dependency patterns that require attention to bandwidth; random scatter/gather is unfriendly.
36
+ - **Operator fusion**: Multiple elementwise steps can be fused into a single kernel; algorithms that repeatedly read/write to memory — "beautiful but intractable" — should be rearranged into a single pass.
37
+
38
+ Eight-dimension minimum criteria (formal terms): **Tensorization** requires the main loop to be batchable; **GEMM-mappability** prioritizes expressing the core computation as GEMM/conv/scan; **complexity** must specify both time and space order; **memory and KV-cache** checks whether intermediate tables, state, and cache can be chunked; **low-precision stability** checks reduction, sorting, and iteration errors; **parallelism and communication** checks dependency graphs and cross-device synchronization; **sparse structure** accepts only structured sparsity; **operator fusion** requires reducing small kernels and memory round-trips.
39
+
40
+ | Algorithm characteristic | GPU classification | Notes |
41
+ |---|---|---|
42
+ | Divide-and-conquer / Merge / FFT | Friendly | Sub-quadratic, batchable, regular structure |
43
+ | Dynamic programming (dependency chains) | Adaptable | Chunking / skew scanning breaks serial dependencies |
44
+ | Backtracking / DFS serial search | Anti-pattern | Unpredictable branching, cannot fill SIMD lanes |
45
+ | Brute force O(2^n) | Anti-pattern | Complexity order itself is intractable |
46
+
47
+ > Used together with `../../references/books/matrix-analysis.md` (GEMM / low-rank decomposition for order reduction), `../../references/books/optimization-ml.md` (first-order / second-order method feasibility), `../../references/books/abstract-algebra.md` (parallel algorithms over semirings / finite fields).
48
+
49
+ ## When NOT to Use
50
+
51
+ - **The problem has a closed-form solution and does not require step-by-step computation** — e.g., the quadratic formula directly gives the answer; algorithmic treatment only adds complexity.
52
+ - **The problem is qualitative rather than procedural** — e.g., "Is this structure elegant?" or "Is this proof insightful?" cannot be reduced to finite steps.
53
+ - **The input is unstructured and cannot be discretized** — e.g., a continuous perceptual data stream cannot directly serve as algorithm input; when preprocessing is more complex than the core problem, algorithmic treatment may not be optimal.
54
+
55
+ ## When to Use
56
+
57
+ - Automating a repetitive process — the same operation must be performed on large volumes of data; manual execution does not scale.
58
+ - Verifying program termination — proving the algorithm halts in a finite number of steps is the cornerstone of reliability.
59
+ - Estimating computational cost — evaluating time/space consumption before large-scale runs to avoid resource exhaustion.
60
+ - Facing combinatorial explosion — the search space grows exponentially with input size, requiring pruning strategies.
61
+ - Judging problem feasibility — determining P / NP-hard / undecidable to decide on a solution strategy.
62
+ - Designing efficient solution procedures — from brute force to elegant algorithms, efficiency differences can span several orders of magnitude.
63
+ - **Designing executable algorithms/operators for GPU** — assessing complexity order, parallelism, memory access, and fusion so the algorithm is truly tractable on hardware.
64
+
65
+ ## Method
66
+
67
+ ### Step 1: Formalize I/O Spec
68
+ Define the input domain, output domain, and constraints. The input specification states data types (integer/floating-point/string/graph), scale range n∈[1,10^6], and validity conditions (preconditions); the output specification states the return type, precision, and boundary handling; constraints cover time/space limits and correctness guarantees (postconditions). Test: if you cannot write down the precondition/postcondition predicates, the specification is not yet formal enough.
69
+
70
+ ### Step 2: Decompose into Sub-problems
71
+ Break the large problem into independently solvable pieces with clear boundaries and well-defined interfaces. Decomposition strategies: by data (processing different subsets), by function (completing different subtasks), by level (coarse-to-fine refinement). Good decomposition makes each sub-problem independently verifiable and the whole recursively verifiable; dependencies between sub-problems must be explicitly annotated to avoid implicit coupling.
72
+
73
+ ### Step 3: Design the Procedure
74
+ Choose an algorithmic paradigm — this is the core decision; choosing wrong wastes all subsequent effort:
75
+
76
+ - **Divide-and-Conquer**: Partition, solve sub-parts, merge. Sub-problems are independent; merge cost is lower than solving the whole. Classics: merge sort, quicksort, Strassen matrix multiplication. Recurrence T(n)=aT(n/b)+f(n), solved by the Master Theorem.
77
+ - **Dynamic Programming (DP)**: Overlapping sub-problems, memoization to avoid repetition. Optimal substructure holds. Classics: shortest paths, knapsack, sequence alignment.
78
+ - **Greedy**: Locally optimal at each step, hoping for global optimality. Greedy-choice property holds. Classics: Dijkstra, Huffman, MST.
79
+ - **Backtracking**: Systematic search, pruning and retreating upon hitting dead ends. Search space has structure. Classics: N-queens, exact TSP, CSP.
80
+ - **Randomized**: Probabilistic shortcuts, trading randomness for efficiency. Deterministic cost is too high. Classics: randomized quicksort, Monte Carlo, Las Vegas.
81
+
82
+ Selection principle: independent → divide-and-conquer; overlapping → DP; greedy property → greedy; structured search → backtracking; deterministic cost too high → randomized. Practical problems often mix multiple paradigms.
83
+
84
+ ### Step 4: Analyze Complexity
85
+ Time O(f(n)), space O(g(n)), distinguishing worst case from average case. Identify basic operation counts, solve recurrences (Master Theorem), and attend to how input distributions affect average-case complexity; beyond O (upper bound), attend to Ω (lower bound) and Θ (tight bound). Complexity analysis is an ongoing assessment during design, not post-hoc verification. Practical significance: for n=10^6, O(n) ≈ 10^6 steps (seconds), O(n²) ≈ 10^12 steps (infeasible), O(2^n) far exceeds the age of the universe.
86
+
87
+ ### Step 5: Prove Correctness
88
+ Use loop invariants, structural induction, termination proofs, and pre/postconditions. An unverified algorithm is a guess. Loop invariant: initialization (holds before the loop), maintenance (preserved by each iteration), termination (invariant plus termination condition yields the postcondition); structural induction: assume correctness of sub-calls and prove the current call; termination: construct a decreasing measure and prove it strictly decreases; Hoare logic: {P} S {Q}.
89
+
90
+ ### Step 6: Check Tractability
91
+ Is the problem in P? NP-hard? Undecidable? P → pursue the optimal exact algorithm; NP-hard → approximation/heuristics with explicit error bounds or probabilistic guarantees; undecidable → find a decidable restricted version. Common NP-hard problems: TSP, graph coloring, subset sum, SAT; common undecidable problems: the halting problem, Hilbert's tenth problem.
92
+
93
+ ### Step 7: Optimize and Improve
94
+ Reduce constant factors, leverage data structures, parallelize — based on bottleneck analysis, not blind tuning. Optimization levels: (1) Algorithm level — switch to a superior paradigm (O(n²) → O(n log n) yields the largest gain); (2) Data structure level — switch to better storage/query structures; (3) Implementation level — caching, parallelism, SIMD, operator fusion; (4) Problem level — reformulate for easier solving (may yield qualitative leaps). Priority: algorithm level > data structure level > implementation level; problem level may enable leaps. Re-verify correctness after every optimization.
95
+
96
+ ## Common Errors
97
+
98
+ | Error | Critique | Correct Approach |
99
+ |-------|----------|-----------------|
100
+ | Assuming exponential algorithms are acceptable | NP-hard problems require heuristics for large n, not exact solutions; 2^50 steps at 1ns each takes 35 years | Use approximation/heuristics for large n with explicit error bounds |
101
+ | Failing to prove termination | Infinite loops are a real risk; hanging is far more dangerous than slow results | Prove termination via a decreasing measure; construct a decreasing function on a well-ordered set |
102
+ | Confusing worst case with average case | Quicksort is worst-case O(n²) but average O(n log n); the worst case can occur in practice | Clearly state the analysis scenario and note assumptions |
103
+ | Confusing existence with constructibility | A solution may exist but be uncomputable; existence ≠ constructibility | Distinguish existence proofs from algorithmic constructions |
104
+ | Underestimating constant factors | O(n log n) with a huge constant may be slower than O(n²) with a small constant | Benchmark empirically; attend to constants and cache effects |
105
+ | Ignoring space complexity | A time-efficient algorithm may exhaust memory; DFS needs O(n) but BFS needs O(2^n) | Analyze both time and space |
106
+ | Premature optimization | Optimizing before proving correctness; the direction may be entirely wrong | Prove correctness first → analyze complexity → then optimize |
107
+ | Ignoring input distribution | Average-case complexity depends on distributional assumptions; random input ≠ real input | State distributional assumptions explicitly; analyze real-world scenarios |
108
+ | Serial / unfusable algorithms on GPU | Unpredictable branching, serial dependency chains, repeated memory reads/writes — "beautiful but intractable" | Adapt to parallel / fusible / sub-quadratic form; pass the GPU eight-dimension gate |
109
+
110
+ ## Operating Procedure
111
+
112
+ When this skill is triggered, the output must include:
113
+
114
+ 1. **Input specification**: `[Input]: [description]` — e.g., `[Input]: unsorted integer array A[1..n], n∈[1,10^6]`
115
+ 2. **Output specification**: `[Output]: [description]` — e.g., `[Output]: A sorted in ascending order`
116
+ 3. **Algorithm paradigm**: `[Paradigm]: [divide-and-conquer/DP/greedy/backtracking/randomized] because [reason]`
117
+ 4. **Complexity**: `[Time]: O([f(n)]) [Space]: O([g(n)]) [Scenario]: [worst/average]`
118
+ 5. **Correctness**: `[Loop invariant/induction strategy]: [content] ✅ proved / ❌ not proved`
119
+ 6. **Tractability**: `[Class]: [P/NP-hard/undecidable] [Response]: [exact/approximate/heuristic/reformulate]`
120
+ 7. **Improvement suggestions**: `[Optimization direction]: [specific suggestions]`
121
+ 8. **[GPU feasibility]** (if used for algorithm/operator design) — complexity order / parallelism / memory access / fusion assessment, annotate as friendly / retrofittable / anti-pattern + adaptation suggestions
122
+
123
+ **The output must not present analysis alone without a conclusion.**
124
+
125
+ ## Relations to Other Skills
126
+
127
+ - **Optimization thinking**: Gradient descent, branch-and-bound, and other optimization algorithms are instances of algorithmic thinking — optimization focuses on the optimal value, while algorithms focus on the steps and cost to reach it.
128
+ - **Transformation thinking**: FFT is a paradigmatic application of algorithmic thinking to transformations — O(n²) → O(n log n); transformations map problems to easily solvable spaces, and algorithms solve them efficiently in the transformed space.
129
+ - **Logical deduction**: Correctness proofs use deductive reasoning (loop invariants, induction) — an algorithm correctness proof is essentially a chain of deductive steps.
130
+ - **Induction and analogy**: Divide-and-conquer uses structural analogy — sub-problems are isomorphic to the original problem — which is precisely the algorithmic embodiment of inductive thinking.
131
+ - **Discrete / Combinatorial thinking**: Algorithms process discrete objects, and combinatorial counting underpins complexity analysis — combinatorial explosion is the core obstacle algorithmic thinking must overcome.
132
+ - **Modern mathematics activation**: `../../references/books/matrix-analysis.md` (GEMM / low-rank decomposition for order reduction), `../../references/books/optimization-ml.md` (GPU feasibility of first-order / second-order methods), `../../references/books/abstract-algebra.md` (parallel algorithms over semirings / finite fields).