math-skill 2.1.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en-US.md +165 -198
- package/README.md +165 -198
- package/agents/math-critic.en.md +28 -26
- package/agents/math-critic.md +33 -33
- package/commands/ask.en.md +10 -0
- package/commands/ask.md +3 -10
- package/design-patterns/attention/equivariant-attention.en.md +72 -0
- package/design-patterns/attention/equivariant-attention.md +72 -0
- package/design-patterns/attention/geometry-aware-attention.en.md +73 -0
- package/design-patterns/attention/geometry-aware-attention.md +72 -0
- package/design-patterns/attention/information-bottleneck-attention.en.md +72 -0
- package/design-patterns/attention/information-bottleneck-attention.md +72 -0
- package/design-patterns/attention/projection-attention.en.md +68 -0
- package/design-patterns/attention/projection-attention.md +68 -0
- package/design-patterns/attention/spectral-attention.en.md +71 -0
- package/design-patterns/attention/spectral-attention.md +71 -0
- package/design-patterns/compression/leverage-score-selection.en.md +71 -0
- package/design-patterns/compression/leverage-score-selection.md +71 -0
- package/design-patterns/compression/low-rank-kv-cache.en.md +60 -0
- package/design-patterns/compression/low-rank-kv-cache.md +60 -0
- package/design-patterns/compression/spectral-token-pruning.en.md +61 -0
- package/design-patterns/compression/spectral-token-pruning.md +61 -0
- package/design-patterns/compression/topology-preserving-compression.en.md +64 -0
- package/design-patterns/compression/topology-preserving-compression.md +64 -0
- package/design-patterns/loss/constraint-penalty.en.md +67 -0
- package/design-patterns/loss/constraint-penalty.md +78 -0
- package/design-patterns/loss/contrastive-loss.en.md +59 -0
- package/design-patterns/loss/contrastive-loss.md +68 -0
- package/design-patterns/loss/information-bottleneck-loss.en.md +69 -0
- package/design-patterns/loss/information-bottleneck-loss.md +74 -0
- package/design-patterns/loss/orthogonality-loss.en.md +56 -0
- package/design-patterns/loss/orthogonality-loss.md +60 -0
- package/design-patterns/loss/variational-loss.en.md +61 -0
- package/design-patterns/loss/variational-loss.md +71 -0
- package/design-patterns/representation/equivariant-split.en.md +87 -0
- package/design-patterns/representation/equivariant-split.md +89 -0
- package/design-patterns/representation/manifold-representation.en.md +85 -0
- package/design-patterns/representation/manifold-representation.md +87 -0
- package/design-patterns/representation/shared-private-decomposition.en.md +84 -0
- package/design-patterns/representation/shared-private-decomposition.md +86 -0
- package/design-patterns/representation/subspace-alignment.en.md +90 -0
- package/design-patterns/representation/subspace-alignment.md +92 -0
- package/design-patterns/routing/graph-routing.en.md +79 -0
- package/design-patterns/routing/graph-routing.md +81 -0
- package/design-patterns/routing/moe-routing.en.md +85 -0
- package/design-patterns/routing/moe-routing.md +87 -0
- package/design-patterns/routing/optimal-transport-routing.en.md +68 -0
- package/design-patterns/routing/optimal-transport-routing.md +72 -0
- package/design-patterns/routing/spectral-clustering-routing.en.md +88 -0
- package/design-patterns/routing/spectral-clustering-routing.md +90 -0
- package/knowledge-base/differential-geometry/connection.en.md +51 -0
- package/knowledge-base/differential-geometry/connection.md +51 -0
- package/knowledge-base/differential-geometry/curvature.en.md +49 -0
- package/knowledge-base/differential-geometry/curvature.md +49 -0
- package/knowledge-base/differential-geometry/geodesic.en.md +51 -0
- package/knowledge-base/differential-geometry/geodesic.md +51 -0
- package/knowledge-base/differential-geometry/manifold.en.md +47 -0
- package/knowledge-base/differential-geometry/manifold.md +47 -0
- package/knowledge-base/differential-geometry/metric-tensor.en.md +50 -0
- package/knowledge-base/differential-geometry/metric-tensor.md +50 -0
- package/knowledge-base/differential-geometry/tangent-space.en.md +48 -0
- package/knowledge-base/differential-geometry/tangent-space.md +48 -0
- package/knowledge-base/information-geometry/fisher-metric.en.md +56 -0
- package/knowledge-base/information-geometry/fisher-metric.md +56 -0
- package/knowledge-base/information-geometry/natural-gradient.en.md +54 -0
- package/knowledge-base/information-geometry/natural-gradient.md +54 -0
- package/knowledge-base/lie-theory/equivariance.en.md +54 -0
- package/knowledge-base/lie-theory/equivariance.md +54 -0
- package/knowledge-base/lie-theory/group-action.en.md +51 -0
- package/knowledge-base/lie-theory/group-action.md +51 -0
- package/knowledge-base/lie-theory/lie-algebra.en.md +51 -0
- package/knowledge-base/lie-theory/lie-algebra.md +51 -0
- package/knowledge-base/lie-theory/lie-group.en.md +51 -0
- package/knowledge-base/lie-theory/lie-group.md +51 -0
- package/knowledge-base/lie-theory/representation.en.md +52 -0
- package/knowledge-base/lie-theory/representation.md +52 -0
- package/knowledge-base/matrix-analysis/low-rank-approximation.en.md +49 -0
- package/knowledge-base/matrix-analysis/low-rank-approximation.md +49 -0
- package/knowledge-base/matrix-analysis/matrix-perturbation.en.md +49 -0
- package/knowledge-base/matrix-analysis/matrix-perturbation.md +49 -0
- package/knowledge-base/matrix-analysis/positive-semidefinite.en.md +50 -0
- package/knowledge-base/matrix-analysis/positive-semidefinite.md +50 -0
- package/knowledge-base/matrix-analysis/projection.en.md +47 -0
- package/knowledge-base/matrix-analysis/projection.md +47 -0
- package/knowledge-base/matrix-analysis/spectral-decomposition.en.md +48 -0
- package/knowledge-base/matrix-analysis/spectral-decomposition.md +48 -0
- package/knowledge-base/optimization/constrained-optimization.en.md +53 -0
- package/knowledge-base/optimization/constrained-optimization.md +53 -0
- package/knowledge-base/optimization/convex-optimization.en.md +50 -0
- package/knowledge-base/optimization/convex-optimization.md +50 -0
- package/knowledge-base/optimization/lagrangian-duality.en.md +50 -0
- package/knowledge-base/optimization/lagrangian-duality.md +50 -0
- package/knowledge-base/optimization/proximal-method.en.md +52 -0
- package/knowledge-base/optimization/proximal-method.md +52 -0
- package/knowledge-base/optimization/riemannian-optimization.en.md +51 -0
- package/knowledge-base/optimization/riemannian-optimization.md +51 -0
- package/knowledge-base/overview.en.md +29 -218
- package/knowledge-base/overview.md +29 -220
- package/knowledge-base/probability/concentration-inequality.en.md +45 -0
- package/knowledge-base/probability/concentration-inequality.md +45 -0
- package/knowledge-base/probability/entropy.en.md +47 -0
- package/knowledge-base/probability/entropy.md +47 -0
- package/knowledge-base/probability/fisher-information.en.md +48 -0
- package/knowledge-base/probability/fisher-information.md +48 -0
- package/knowledge-base/probability/information-bottleneck.en.md +49 -0
- package/knowledge-base/probability/information-bottleneck.md +49 -0
- package/knowledge-base/probability/kl-divergence.en.md +51 -0
- package/knowledge-base/probability/kl-divergence.md +51 -0
- package/knowledge-base/topology/euler-characteristic.en.md +54 -0
- package/knowledge-base/topology/euler-characteristic.md +54 -0
- package/knowledge-base/topology/fundamental-group.en.md +52 -0
- package/knowledge-base/topology/fundamental-group.md +52 -0
- package/knowledge-base/topology/persistent-homology.en.md +54 -0
- package/knowledge-base/topology/persistent-homology.md +54 -0
- package/lenses/algorithmic.en.md +49 -0
- package/lenses/algorithmic.md +49 -0
- package/lenses/axiomatization.en.md +48 -0
- package/lenses/axiomatization.md +48 -0
- package/lenses/categorical.en.md +48 -0
- package/lenses/categorical.md +48 -0
- package/lenses/causal.en.md +49 -0
- package/lenses/causal.md +49 -0
- package/lenses/duality.en.md +47 -0
- package/lenses/duality.md +47 -0
- package/lenses/game.en.md +50 -0
- package/lenses/game.md +50 -0
- package/lenses/geometric.en.md +53 -0
- package/lenses/geometric.md +53 -0
- package/lenses/local-to-global.en.md +52 -0
- package/lenses/local-to-global.md +52 -0
- package/lenses/perturbation.en.md +51 -0
- package/lenses/perturbation.md +51 -0
- package/lenses/probabilistic.en.md +48 -0
- package/lenses/probabilistic.md +48 -0
- package/lenses/projection.en.md +50 -0
- package/lenses/projection.md +50 -0
- package/lenses/spectral.en.md +52 -0
- package/lenses/spectral.md +52 -0
- package/lenses/symmetry.en.md +49 -0
- package/lenses/symmetry.md +49 -0
- package/lenses/topological.en.md +48 -0
- package/lenses/topological.md +48 -0
- package/lenses/variational.en.md +48 -0
- package/lenses/variational.md +48 -0
- package/package.json +9 -3
- package/references/agentic-workflow.en.md +1 -1
- package/references/agentic-workflow.md +1 -1
- package/references/books/abstract-algebra.en.md +124 -0
- package/references/books/abstract-algebra.md +22 -22
- package/references/books/algebraic-geometry-rising-sea.en.md +171 -0
- package/references/books/algebraic-geometry-rising-sea.md +11 -11
- package/references/books/differential-geometry.en.md +140 -0
- package/references/books/differential-geometry.md +19 -19
- package/references/books/matrix-analysis.en.md +146 -0
- package/references/books/matrix-analysis.md +10 -10
- package/references/books/micro-lie-theory.en.md +116 -0
- package/references/books/micro-lie-theory.md +17 -17
- package/references/books/optimization-ml.en.md +163 -0
- package/references/books/optimization-ml.md +7 -8
- package/references/books/smooth-manifolds.en.md +105 -0
- package/references/books/smooth-manifolds.md +14 -14
- package/references/gpu-friendly-math.en.md +23 -10
- package/references/gpu-friendly-math.md +17 -4
- package/references/inspiration.en.md +1 -1
- package/references/inspiration.md +2 -2
- package/skills/math-research-activator/SKILL.en.md +195 -114
- package/skills/math-research-activator/SKILL.md +194 -119
- package/skills/math-research-activator/original-texts.en.md +9 -9
- package/skills/math-research-activator/original-texts.md +11 -11
- package/commands/abstraction.md +0 -11
- package/commands/algorithmic-thinking.md +0 -11
- package/commands/axiomatization.md +0 -11
- package/commands/causal-inference.md +0 -11
- package/commands/discrete-combinatorial.md +0 -11
- package/commands/game-theory.md +0 -11
- package/commands/induction-analogy.md +0 -11
- package/commands/information-theory.md +0 -11
- package/commands/logic-deduction.md +0 -11
- package/commands/modeling.md +0 -11
- package/commands/optimization.md +0 -11
- package/commands/probability-statistics.md +0 -11
- package/commands/symmetry-invariance.md +0 -11
- package/commands/topological-thinking.md +0 -11
- package/commands/transformation.md +0 -11
- package/skills/abstraction/SKILL.en.md +0 -117
- package/skills/abstraction/SKILL.md +0 -121
- package/skills/abstraction/original-texts.en.md +0 -163
- package/skills/abstraction/original-texts.md +0 -175
- package/skills/algorithmic-thinking/SKILL.en.md +0 -132
- package/skills/algorithmic-thinking/SKILL.md +0 -138
- package/skills/algorithmic-thinking/original-texts.en.md +0 -253
- package/skills/algorithmic-thinking/original-texts.md +0 -256
- package/skills/axiomatization/SKILL.en.md +0 -144
- package/skills/axiomatization/SKILL.md +0 -151
- package/skills/axiomatization/original-texts.en.md +0 -154
- package/skills/axiomatization/original-texts.md +0 -160
- package/skills/causal-inference/SKILL.en.md +0 -147
- package/skills/causal-inference/SKILL.md +0 -151
- package/skills/causal-inference/original-texts.en.md +0 -136
- package/skills/causal-inference/original-texts.md +0 -167
- package/skills/discrete-combinatorial/SKILL.en.md +0 -124
- package/skills/discrete-combinatorial/SKILL.md +0 -131
- package/skills/discrete-combinatorial/original-texts.en.md +0 -184
- package/skills/discrete-combinatorial/original-texts.md +0 -185
- package/skills/game-theory/SKILL.en.md +0 -117
- package/skills/game-theory/SKILL.md +0 -123
- package/skills/game-theory/original-texts.en.md +0 -131
- package/skills/game-theory/original-texts.md +0 -131
- package/skills/induction-analogy/SKILL.en.md +0 -145
- package/skills/induction-analogy/SKILL.md +0 -152
- package/skills/induction-analogy/original-texts.en.md +0 -140
- package/skills/induction-analogy/original-texts.md +0 -154
- package/skills/information-theory/SKILL.en.md +0 -134
- package/skills/information-theory/SKILL.md +0 -140
- package/skills/information-theory/original-texts.en.md +0 -127
- package/skills/information-theory/original-texts.md +0 -127
- package/skills/logic-deduction/SKILL.en.md +0 -130
- package/skills/logic-deduction/SKILL.md +0 -135
- package/skills/logic-deduction/original-texts.en.md +0 -160
- package/skills/logic-deduction/original-texts.md +0 -173
- package/skills/modeling/SKILL.en.md +0 -135
- package/skills/modeling/SKILL.md +0 -139
- package/skills/modeling/original-texts.en.md +0 -162
- package/skills/modeling/original-texts.md +0 -165
- package/skills/optimization/SKILL.en.md +0 -129
- package/skills/optimization/SKILL.md +0 -135
- package/skills/optimization/original-texts.en.md +0 -167
- package/skills/optimization/original-texts.md +0 -168
- package/skills/probability-statistics/SKILL.en.md +0 -146
- package/skills/probability-statistics/SKILL.md +0 -151
- package/skills/probability-statistics/original-texts.en.md +0 -191
- package/skills/probability-statistics/original-texts.md +0 -193
- package/skills/symmetry-invariance/SKILL.en.md +0 -135
- package/skills/symmetry-invariance/SKILL.md +0 -139
- package/skills/symmetry-invariance/original-texts.en.md +0 -206
- package/skills/symmetry-invariance/original-texts.md +0 -221
- package/skills/topological-thinking/SKILL.en.md +0 -124
- package/skills/topological-thinking/SKILL.md +0 -128
- package/skills/topological-thinking/original-texts.en.md +0 -134
- package/skills/topological-thinking/original-texts.md +0 -164
- package/skills/transformation/SKILL.en.md +0 -120
- package/skills/transformation/SKILL.md +0 -124
- package/skills/transformation/original-texts.en.md +0 -204
- package/skills/transformation/original-texts.md +0 -216
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
# 数学出处与经典文献 / Mathematical Sources and Classic Texts
|
|
2
|
-
|
|
3
|
-
## 伽罗瓦理论 / Galois Theory (1830s)
|
|
4
|
-
|
|
5
|
-
> "伽罗瓦理论的深刻之处在于:它将'方程是否有根式解'的问题,转化为'置换群是否可解'的结构问题。"
|
|
6
|
-
> "The profundity of Galois theory: it transforms the question 'can an equation be solved by radicals?' into the structural question 'is the permutation group solvable?'"
|
|
7
|
-
|
|
8
|
-
**抽象范式**:伽罗瓦理论是数学史上最早的系统抽象——从具体的方程求解,上升到群的对称性结构。
|
|
9
|
-
- 根的置换群(permutation group of roots)决定了方程的可解性
|
|
10
|
-
- 伽罗瓦对应(Galois correspondence):子群 ↔ 子域,将代数与结构直接联系
|
|
11
|
-
- 影响深远:开启了"用结构代替计算"的思维方式,为抽象代数奠定基础
|
|
12
|
-
|
|
13
|
-
**历史**:Evariste Galois (1811–1832),生前未获认可,手稿由 Liouville 于 1846 年发表。
|
|
14
|
-
|
|
15
|
-
## 戴德金与诺特 / Dedekind & Noether — 从数到结构 / From Numbers to Structures
|
|
16
|
-
|
|
17
|
-
> "戴德金将整数从'计数工具'抽象为'环的理想';诺特将这一切系统化,使理想成为代数的核心对象。"
|
|
18
|
-
> "Dedekind abstracted integers from 'counting tools' into 'ideals of rings'; Noether systematized this, making ideals the central objects of algebra."
|
|
19
|
-
|
|
20
|
-
**关键贡献**:
|
|
21
|
-
- **Dedekind (1831–1916)**:理想(ideals)理论的创始人——将"整除"抽象为"包含关系",将数论提升到结构层面
|
|
22
|
-
- **Emmy Noether (1882–1935)**:
|
|
23
|
-
- 诺特环(Noetherian rings):升链条件将"有限性"从具体对象抽象为结构性质
|
|
24
|
-
- 诺定理(Noether's theorem, 1918):物理中的对称性 ↔ 守恒律——物理学中抽象结构的典范
|
|
25
|
-
- 将抽象代数从"计算性"转向"结构性"
|
|
26
|
-
|
|
27
|
-
> "Noether 的教学模式:'Es steht schon bei Dedekind'(Dedekind 已经写过了)——她总是追溯结构的思想根源。"
|
|
28
|
-
|
|
29
|
-
## 范畴论 / Category Theory (Eilenberg & Mac Lane, 1945)
|
|
30
|
-
|
|
31
|
-
> "范畴论的核心思想是:研究对象之间的态射(映射)比研究对象本身更重要。"
|
|
32
|
-
> "The key idea of category theory: studying the morphisms (maps) between objects is more important than studying the objects themselves."
|
|
33
|
-
|
|
34
|
-
**核心概念**:
|
|
35
|
-
- **对象(Objects)** 和 **态射(Morphisms)**
|
|
36
|
-
- **函子(Functors)**:范畴之间的映射
|
|
37
|
-
- **自然变换(Natural Transformations)**:函子之间的映射
|
|
38
|
-
- **泛性质(Universal Properties)**:用关系定义对象
|
|
39
|
-
|
|
40
|
-
**抽象的意义**:范畴论是"数学的数学"——它抽象到可以描述数学本身的结构。
|
|
41
|
-
|
|
42
|
-
## 米田引理 / Yoneda Lemma (1954)
|
|
43
|
-
|
|
44
|
-
> "一个对象完全由它与其他对象之间的关系所决定——这是范畴论的基本定理。"
|
|
45
|
-
> "An object is completely determined by its relationships to all other objects — this is the fundamental theorem of category theory."
|
|
46
|
-
|
|
47
|
-
**数学含义**:
|
|
48
|
-
- 形式化表述:Hom(Hom(A, —), F) ≅ F(A)——函子的自然变换与函子在 A 处的取值一一对应
|
|
49
|
-
- 哲学意义:要了解一个事物,只需观察它与一切其他事物的交互——"你由你的关系所定义"
|
|
50
|
-
- Yoneda 嵌入:每个对象 A ↦ Hom(—, A),对象可完全嵌入到其"关系世界"中
|
|
51
|
-
- 被称为范畴论的"第一定理"(first theorem),地位相当于集合论中的外延公理
|
|
52
|
-
|
|
53
|
-
**历史**:首次出现在 Nobuo Yoneda 的未发表笔记中,后由 Mac Lane 在 1954 年正式阐述。
|
|
54
|
-
|
|
55
|
-
## 布尔巴基 / Bourbaki (1935–)
|
|
56
|
-
|
|
57
|
-
> "布尔巴基用'结构'作为统一语言重写了二十世纪数学——从母结构(代数、序、拓扑)出发,一切皆结构。"
|
|
58
|
-
> "Bourbaki rewrote 20th-century mathematics with 'structures' as a unifying language — from mother structures (algebra, order, topology), everything is structure."
|
|
59
|
-
|
|
60
|
-
**核心思想**:
|
|
61
|
-
- 三大母结构(mother structures):代数结构(algebraic)、序结构(order)、拓扑结构(topological)
|
|
62
|
-
- 复合结构(multiple structures):由母结构组合而来——拓扑群、有序域等
|
|
63
|
-
- 《数学原理》(Éléments de mathématique):40 余卷的系统化重写
|
|
64
|
-
- 影响深远:定义了现代数学教材的组织方式与抽象风格
|
|
65
|
-
|
|
66
|
-
**争议**:布尔巴基的结构主义偏向过于抽象,忽视了概率论与计算数学——但也正是这种抽象化推动了范畴论的诞生。
|
|
67
|
-
|
|
68
|
-
## 代数结构 / Algebraic Structures
|
|
69
|
-
|
|
70
|
-
抽象代数展示了不同数学对象之间的深层共性:
|
|
71
|
-
|
|
72
|
-
| 结构 | 运算要求 | 例子 |
|
|
73
|
-
|------|---------|------|
|
|
74
|
-
| 半群 (Semigroup) | 封闭、结合 | 函数复合、字符串拼接 |
|
|
75
|
-
| 幺半群 (Monoid) | 半群 + 单位元 | 自然数加法、列表拼接(含空列表) |
|
|
76
|
-
| 群 (Group) | 幺半群 + 逆元 | 对称群、整数加法群 |
|
|
77
|
-
| 环 (Ring) | 群(加法)+ 半群(乘法)+ 分配律 | 整数环、多项式环 |
|
|
78
|
-
| 域 (Field) | 环 + 乘法逆元(非零元) | 有理数域、实数域 |
|
|
79
|
-
| 向量空间 (Vector Space) | 域上的加法群 + 标量乘法 | ℝⁿ, 函数空间 |
|
|
80
|
-
|
|
81
|
-
**中间结构的意义**:半群和幺半群并非"不完整的群"——它们在自动机理论(automata theory)、形式语言(formal languages)、字符串处理中本身就是核心对象。抽象不是追求"最完整",而是提取恰好所需的性质。
|
|
82
|
-
|
|
83
|
-
**抽象的力量**:一旦在抽象层面证明了某个结论,它就自动适用于所有满足该结构的实例。
|
|
84
|
-
|
|
85
|
-
## 泛代数 / Universal Algebra (Birkhoff, 1935)
|
|
86
|
-
|
|
87
|
-
> "泛代数的核心问题是:什么样的等式类(equational classes)可以被一组等式公理所定义?"
|
|
88
|
-
> "The central question of universal algebra: which equational classes can be defined by a set of equational axioms?"
|
|
89
|
-
|
|
90
|
-
**关键贡献**:
|
|
91
|
-
- **Birkhoff 定理**:一个代数类是等式类(variety) iff 它对同态像、子代数、直积封闭(HSP 定理)
|
|
92
|
-
- 系统地研究"代数结构本身"——不是某个具体群或环,而是"一切满足给定公理的结构的共同性质"
|
|
93
|
-
- 泛代数是范畴论的前驱:泛性质、自由对象等概念在此已经有了雏形
|
|
94
|
-
- 与范畴论的关系:等式类 = 由自由代数生成的范畴中的泛对象
|
|
95
|
-
|
|
96
|
-
## 表示论 / Representation Theory (Frobenius, 1896–)
|
|
97
|
-
|
|
98
|
-
> "表示论将抽象群'实现'为具体的线性变换——让不可见的对称性变得可见。"
|
|
99
|
-
> "Representation theory 'realizes' abstract groups as concrete linear transformations — making invisible symmetries visible."
|
|
100
|
-
|
|
101
|
-
**核心思想**:
|
|
102
|
-
- 群表示(group representation):群 G → GL(V),将抽象群元素映射为矩阵
|
|
103
|
-
- Frobenius (1849–1917):开创群的特征标理论(character theory),用迹函数捕捉不可约表示
|
|
104
|
-
- 不可约表示(irreducible representations):群的"原子"——一切表示由它们组合
|
|
105
|
-
- Schur 引理、Maschke 定理等构成了半单代数的完整理论
|
|
106
|
-
|
|
107
|
-
**抽象的双重意义**:一方面,表示论让抽象对象变得可计算;另一方面,表示的分类本身就是更高层次的抽象问题。
|
|
108
|
-
|
|
109
|
-
## 自由对象与泛构造 / Free Objects and Universal Constructions
|
|
110
|
-
|
|
111
|
-
> "自由对象是'没有任何额外关系'的最一般的对象——它仅由公理强制的关系所决定。"
|
|
112
|
-
> "A free object is the most general object with 'no extra relations' — determined only by relations forced by axioms."
|
|
113
|
-
|
|
114
|
-
**核心概念**:
|
|
115
|
-
- **自由群(Free group)**:由字母表生成,除群的公理外无任何额外关系
|
|
116
|
-
- **自由幺半群(Free monoid)**:就是字符串集合——字符串拼接是"最自由的"结合运算
|
|
117
|
-
- **泛性质表述**:自由对象 F(A) 满足——任意映射 A → X(X 为目标结构中的对象)唯一延伸为 F(A) → X 的态射
|
|
118
|
-
- **左伴随(Left adjoint)**:遗忘函子(forgetful functor)的左伴随就是自由对象——抽象的"最一般解"
|
|
119
|
-
|
|
120
|
-
**意义**:自由对象展示了泛构造的典型模式——用"最少的约束"定义"最一般的解",然后通过附加关系得到更具体的对象。
|
|
121
|
-
|
|
122
|
-
## 格罗滕迪克与概形 / Grothendieck & Schemes (1950s–60s)
|
|
123
|
-
|
|
124
|
-
> "格罗滕迪克将代数几何彻底重构:不再研究具体曲线,而是研究概形——最一般的'空间'概念。"
|
|
125
|
-
> "Grothendieck completely reconstructed algebraic geometry: no longer studying specific curves, but schemes — the most general notion of 'space'."
|
|
126
|
-
|
|
127
|
-
**革命性抽象**:
|
|
128
|
-
- **概形(Schemes)**:将代数簇(algebraic varieties)推广到允许零因子、任意基的改变——"空间"不再是点集,而是环的谱(spectrum of a ring)
|
|
129
|
-
- **拓扑斯(Topoi)**:比拓扑空间更一般的"空间"概念——一个拓扑斯就是一个范畴,足以支撑内部逻辑
|
|
130
|
-
- **动机(Motives)**:猜想中的"万能上同调理论"——不同上同调理论的共同根源
|
|
131
|
-
- **泛构造哲学**:Grothendieck 总是先找到"最一般"的框架,再在其中解决具体问题
|
|
132
|
-
|
|
133
|
-
**影响**:EGA/SGA 四千余页的重写,使代数几何成为最抽象也最强大的数学分支之一。Weil 猜想(Weil conjectures)的证明正是这一抽象框架的直接成果。
|
|
134
|
-
|
|
135
|
-
## 拓扑学 / Topology
|
|
136
|
-
|
|
137
|
-
> "拓扑学是研究在连续变形下保持不变的性质的学科。"
|
|
138
|
-
> "Topology studies properties that remain unchanged under continuous deformations."
|
|
139
|
-
|
|
140
|
-
**抽象层次**:
|
|
141
|
-
- 度量空间 → 拓扑空间:去掉距离,只保留"开集"概念
|
|
142
|
-
- 连续函数 → 态射:去掉 ε-δ,只保留"开集的原像是开集"
|
|
143
|
-
- 同胚 → 等价:拓扑意义下"相同"的空间
|
|
144
|
-
|
|
145
|
-
**经典案例**:咖啡杯和甜甜圈在拓扑意义下是同构的——它们都有一个洞。
|
|
146
|
-
|
|
147
|
-
## 同伦类型论 / Homotopy Type Theory (Voevodsky, 2009–)
|
|
148
|
-
|
|
149
|
-
> "同伦类型论的唯一性公理宣称:同构的结构就是相同的——这是抽象的终极形式。"
|
|
150
|
-
> "The univalence axiom of homotopy type theory asserts: isomorphic structures are identical — the ultimate form of abstraction."
|
|
151
|
-
|
|
152
|
-
**核心思想**:
|
|
153
|
-
- **唯一性公理(Univalence Axiom)**:(A ≃ B) ≃ (A = B)——同构与相等等价
|
|
154
|
-
- 哲学冲击:如果两个结构在所有可观测性质上一致,它们就"是"同一个——没有"不可观测的"同一性
|
|
155
|
-
- **同伦层级(h-levels)**:命题(h-level 1)、集合(h-level 2)、群对象(h-level 3)……——将经典逻辑与拓扑直觉统一
|
|
156
|
-
- Voevodsky (1966–2017):Fields 奖得主,后期致力于将数学建立在计算可靠性更高的新基础之上
|
|
157
|
-
|
|
158
|
-
**与范畴论的关系**:同伦类型论可视为范畴论的"内部语言"——在 (∞,1)-范畴的语境中,唯一性公理是自然的。
|
|
159
|
-
|
|
160
|
-
## 抽象的本质 / The Nature of Abstraction
|
|
161
|
-
|
|
162
|
-
> "所谓抽象,就是忽略具体的、偶然的特征,提取一般的、本质的结构。"
|
|
163
|
-
> "Abstraction means ignoring specific, contingent features and extracting general, essential structures."
|
|
164
|
-
|
|
165
|
-
抽象不是远离现实,而是深入现实——通过找到不同事物的共同结构,我们可以用统一的框架处理它们。
|
|
166
|
-
|
|
167
|
-
**抽象的谱系**:
|
|
168
|
-
- Galois (1830s):方程 → 群结构
|
|
169
|
-
- Dedekind (1870s):数 → 理想
|
|
170
|
-
- Birkhoff (1935):具体代数 → 等式类
|
|
171
|
-
- Eilenberg–Mac Lane (1945):具体数学 → 范畴
|
|
172
|
-
- Grothendieck (1960s):具体空间 → 概形与拓扑斯
|
|
173
|
-
- Voevodsky (2010s):同构 → 同一
|
|
174
|
-
|
|
175
|
-
每一次抽象,都让我们看到更深的结构,处理更广的问题。
|
|
@@ -1,132 +0,0 @@
|
|
|
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).
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: algorithmic-thinking
|
|
3
|
-
description: |
|
|
4
|
-
触发:问题需要有限步骤求解、算法设计、复杂度分析(时间/空间)、可行性与并行性评估(P/NP-hard/不可判定);或需证明终止性/正确性;或为 GPU 设计可执行算法/算子(评估复杂度阶、并行度、访存与融合)时调用。
|
|
5
|
-
English: 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).
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
> **语言路由**:若用户消息为英文,请读取并遵循同目录下的 `SKILL.en.md`,按其操作规程以英文输出;中文消息则继续使用本文件。
|
|
9
|
-
|
|
10
|
-
# 🖥️ 算法与计算思想 / Algorithmic Thinking
|
|
11
|
-
|
|
12
|
-
> "算法是思想的自动化——将洞察转化为可重复执行的精确步骤。"
|
|
13
|
-
> "An algorithm is the automation of thought — turning insight into precisely repeatable steps."
|
|
14
|
-
>
|
|
15
|
-
> —— 计算理论、算法分析、复杂度理论 / Computability Theory, Algorithm Analysis, Complexity Theory
|
|
16
|
-
|
|
17
|
-
## 核心原则 / Core Principle
|
|
18
|
-
|
|
19
|
-
**把问题拆解为可执行步骤,评估代价,判断可行性。算法思想的第一原则不是"如何求解",而是"是否可解、代价几何"——某些问题本质困难(NP 完全),某些本质不可解(不可判定),了解这些极限与找到解同样重要。**
|
|
20
|
-
|
|
21
|
-
**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.**
|
|
22
|
-
|
|
23
|
-
> **数学形式化 / Mathematical Formalization**
|
|
24
|
-
>
|
|
25
|
-
> 图灵机 M: Σ* → Σ* 在有限步骤内停机。时间复杂度 T(n) = 长度为 n 的输入的最大执行步数;空间复杂度 S(n) = 最大使用单元数。丘奇-图灵论题:任何可计算的都可由图灵机计算。
|
|
26
|
-
>
|
|
27
|
-
> 三级层次:可计算(算法存在)→ 可行(多项式时间算法存在)→ 难解(仅指数时间或无算法)。可计算但不可行在实践中等同不可计算——蛮力 2^n 对 n=100 毫无价值。P vs NP 正是可行与难解的分界。
|
|
28
|
-
>
|
|
29
|
-
> 复杂度符号:O(f(n)) 上界,Ω(f(n)) 下界,Θ(f(n)) 精确界。常见递推: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)。复杂度类:O(1)⊂O(log n)⊂O(n)⊂O(n log n)⊂O(n^k)⊂O(2^n)⊂O(n!)。
|
|
30
|
-
>
|
|
31
|
-
> 复杂度类定义:P = 多项式时间可判定;NP-hard = 至少与所有 NP 问题同等困难;不可判定 = 无任何算法可判定。NP-hard 应对:近似(误差界限)或启发式(概率保证);不可判定应对:寻找可判定的受限版本。
|
|
32
|
-
>
|
|
33
|
-
> 循环不变量:每次迭代前后成立的性质,加终止条件蕴含输出正确。Hoare 逻辑:{P} S {Q}——前置条件 P 经语句 S 产生后置条件 Q。
|
|
34
|
-
|
|
35
|
-
## GPU 友好性 / GPU-Friendliness(横切检查)
|
|
36
|
-
|
|
37
|
-
算法思想是与 GPU 最直接相关的武器——复杂度阶、并行度、访存/通信、算子融合直接决定一个算法能否在 GPU 上高效跑起来。每个算法须过 `../../references/gpu-friendly-math.md` 八维门:
|
|
38
|
-
|
|
39
|
-
- **复杂度阶**:亚二次 O(n log n)/O(n) 友好(吃满并行核);O(n²) 边界(GEMM 例外,Tensor Core 可救);O(2^n)/O(n!) 反模式。
|
|
40
|
-
- **并行与通信**:分治/数据并行友好(子问题独立、可批量);动规的依赖链、回溯的串行搜索需改造(分块/斜扫描)。
|
|
41
|
-
- **显存与 KV-Cache / 并行与通信**:coalesced 访问友好;butterfly 归约、前缀扫描的依赖需注意带宽;随机 scatter/gather 不友好。
|
|
42
|
-
- **算子融合**:多步 elementwise 可融合为单 kernel;反复读写显存的"美丽但不可算"算法应重排为一次过。
|
|
43
|
-
|
|
44
|
-
八维最低判定(正式术语):**张量化**要求主循环可批量化;**GEMM 可映射**优先把核心计算写成 GEMM/conv/scan;**复杂度**必须给时间与空间阶;**显存与 KV-Cache**检查中间表、状态、缓存是否可分块;**低精度稳定**检查归约、排序、迭代误差;**并行与通信**检查依赖图与跨设备同步;**稀疏结构**只接受结构化稀疏;**算子融合**要求减少小 kernel 与往返显存。
|
|
45
|
-
|
|
46
|
-
| 算法特征 | GPU 分类 | 说明 |
|
|
47
|
-
|---|---|---|
|
|
48
|
-
| 分治/归并/FFT | 友好 | 亚二次、可批量、结构规则 |
|
|
49
|
-
| 动规(依赖链) | 可改造 | 分块/斜扫描打破串行依赖 |
|
|
50
|
-
| 回溯/DFS 串行搜索 | 反模式 | 分支不可预测、无法填满 SIMD |
|
|
51
|
-
| 蛮力 O(2^n) | 反模式 | 复杂度阶本身不可算 |
|
|
52
|
-
|
|
53
|
-
> 配合 `../../references/books/matrix-analysis.md`(GEMM/低秩分解降阶)、`../../references/books/optimization-ml.md`(一阶/二阶法可行性)、`../../references/books/abstract-algebra.md`(半环/有限域上的并行算法)。
|
|
54
|
-
|
|
55
|
-
## 不适用场景 / When NOT to Use
|
|
56
|
-
|
|
57
|
-
- **问题有闭式解,不需要逐步计算**——如二次方程求根公式直接给答案,算法化反增复杂度。
|
|
58
|
-
- **问题本质是定性的而非程序性的**——如"这个结构是否优美""这个证明是否有洞察力"无法化为有限步骤。
|
|
59
|
-
- **输入无结构、无法离散化**——如连续感知数据流无法直接作为算法输入;预处理比核心问题更复杂时算法化未必最优。
|
|
60
|
-
|
|
61
|
-
## 何时使用 / When to Use
|
|
62
|
-
|
|
63
|
-
- 需要自动化重复过程——同一操作对大量数据反复执行,手动不可扩展。
|
|
64
|
-
- 需要验证程序终止——证明算法在有限步内停机,是可靠性的基石。
|
|
65
|
-
- 需要估算计算代价——大规模运行前评估时间/空间消耗,避免资源耗尽。
|
|
66
|
-
- 面对组合爆炸——搜索空间随输入指数增长,需剪枝策略。
|
|
67
|
-
- 需要判断问题可行性——确定 P / NP-hard / 不可判定,决定求解策略。
|
|
68
|
-
- 需要设计高效求解步骤——从蛮力到精巧算法,效率差异可达数个量级。
|
|
69
|
-
- **为 GPU 设计可执行算法/算子**——评估复杂度阶、并行度、访存与融合,使算法在硬件上真正可算。
|
|
70
|
-
|
|
71
|
-
## 方法流程 / Method
|
|
72
|
-
|
|
73
|
-
### 第一步:形式化输入输出规格 / Formalize I/O Spec
|
|
74
|
-
定义输入域、输出域、约束条件。输入规格明确数据类型(整数/浮点/字符串/图)、规模范围 n∈[1,10^6]、合法性条件(前置条件);输出规格明确返回类型、精度、边界处理;约束覆盖时间/空间限制与正确性保证(后置条件)。检验:若写不出前置/后置条件谓词,则规格尚未足够形式化。
|
|
75
|
-
|
|
76
|
-
### 第二步:分解子问题 / Decompose into Sub-problems
|
|
77
|
-
将大问题拆为可独立求解的小块,子问题边界清晰、接口明确。分解策略:按数据(处理不同子集)、按功能(完成不同子任务)、按层次(先粗后细逐层精化)。好的分解使每个子问题可独立验证,整体可递归验证;子问题间依赖须显式标注,避免隐式耦合。
|
|
78
|
-
|
|
79
|
-
### 第三步:设计程序 / Design the Procedure
|
|
80
|
-
选择算法范式——核心决策,选错则后续努力白费:
|
|
81
|
-
|
|
82
|
-
- **分治 (Divide-and-Conquer)**:分割、求解子部分、合并。子问题独立、合并代价低于整体。经典:归并/快速排序、Strassen 矩阵乘。递推 T(n)=aT(n/b)+f(n) 由主定理求解。
|
|
83
|
-
- **动态规划 (DP)**:重叠子问题、备忘录化避免重复。最优子结构成立。经典:最短路、背包、序列对齐。
|
|
84
|
-
- **贪心 (Greedy)**:每步局部最优,期望全局。贪心选择性质成立。经典:Dijkstra、Huffman、MST。
|
|
85
|
-
- **回溯 (Backtracking)**:系统性搜索、遇死路剪枝回退。搜索空间有结构。经典:N 皇后、TSP 精确解、CSP。
|
|
86
|
-
- **随机化 (Randomized)**:概率捷径,以随机换效率。确定性代价过高。经典:随机快排、Monte Carlo、Las Vegas。
|
|
87
|
-
|
|
88
|
-
选择原则:独立→分治、重叠→动规、贪心性质→贪心、结构化搜索→回溯、确定性代价过高→随机化。实际问题常混合多种范式。
|
|
89
|
-
|
|
90
|
-
### 第四步:分析复杂度 / Analyze Complexity
|
|
91
|
-
时间 O(f(n))、空间 O(g(n)),区分最坏与平均。识别基本操作计数、求解递推(主定理)、关注输入分布对平均复杂度的影响;除 O(上界)外关注 Ω(下界)与 Θ(精确界)。复杂度分析是设计中的持续评估,非事后验证。实际意义:n=10^6 时 O(n)≈10^6 步(秒级),O(n²)≈10^12 步(不可行),O(2^n) 远超宇宙年龄。
|
|
92
|
-
|
|
93
|
-
### 第五步:证明正确性 / Prove Correctness
|
|
94
|
-
使用循环不变量、结构归纳、终止证明、前置/后置条件。未经证明的算法是猜测。循环不变量:初始化(循环前成立)、维护(每次迭代保持)、终止(不变量加终止条件给后置条件);结构归纳:假设子调用正确证当前调用;终止:构造递减度量证其严格递减;Hoare 逻辑:{P} S {Q}。
|
|
95
|
-
|
|
96
|
-
### 第六步:检查可行性 / Check Tractability
|
|
97
|
-
问题属 P?NP-hard?不可判定?P → 追求最优精确算法;NP-hard → 近似/启发式,明确误差界限或概率保证;不可判定 → 寻找可判定的受限版本。常见 NP-hard:TSP、图着色、子集和、SAT;常见不可判定:停机问题、希尔伯特第十问题。
|
|
98
|
-
|
|
99
|
-
### 第七步:优化与改进 / Optimize and Improve
|
|
100
|
-
减少常数因子、利用数据结构、并行化,基于瓶颈分析而非盲目调参。优化层次:(1) 算法级——换更优范式(O(n²)→O(n log n) 收益最大);(2) 数据结构级——换更优存储/查询;(3) 实现级——缓存、并行、SIMD、算子融合;(4) 问题级——换表述使更易求解(可能质的飞跃)。优先级:算法级 > 数据结构级 > 实现级,问题级可能跃迁。每次优化后重新验证正确性。
|
|
101
|
-
|
|
102
|
-
## 常见错误 / Common Errors
|
|
103
|
-
|
|
104
|
-
| 错误 / Error | 批评 / Critique | 正确做法 / Correct Approach |
|
|
105
|
-
|---|---|---|
|
|
106
|
-
| 假设指数算法可接受 | NP-hard 对大 n 需启发式而非精确;2^50 步即使每步 1ns 需 35 年 | 对大 n 用近似/启发式,明确误差界限 |
|
|
107
|
-
| 未证明终止性 | 无限循环是真实风险,挂起远比慢结果危险 | 用递减度量证终止,构造良序集上递减函数 |
|
|
108
|
-
| 混淆最坏与平均情况 | 快排最坏 O(n²) 但平均 O(n log n),最坏可能在实中出现 | 明确分析场景,注明假设 |
|
|
109
|
-
| 混淆存在性与可构造性 | 解可能存在但不可计算;存在性≠可构造性 | 区分存在性证明与算法构造 |
|
|
110
|
-
| 低估常数因子 | 巨大常数的 O(n log n) 可能比小常数 O(n²) 慢 | 实测比较,关注常数与缓存效应 |
|
|
111
|
-
| 忽略空间复杂度 | 时间高效的算法可能爆内存;DFS 需 O(n) 但 BFS 需 O(2^n) | 同时分析时间与空间 |
|
|
112
|
-
| 过早优化 | 未证正确就优化,方向可能全错 | 先证正确→析复杂度→再优化 |
|
|
113
|
-
| 忽视输入分布 | 平均复杂度依赖分布假设,随机输入≠实际输入 | 标明分布假设,分析实际场景 |
|
|
114
|
-
| 串行/不可融合算法上 GPU | 分支不可预测、依赖链串行、反复读写显存——"美但不可算" | 改造为并行/可融合/亚二次,过 GPU 八维门 |
|
|
115
|
-
|
|
116
|
-
## 操作规程 / Operating Procedure
|
|
117
|
-
|
|
118
|
-
当本 skill 被触发时,输出必须包含:
|
|
119
|
-
|
|
120
|
-
1. **输入规格**:`[输入]: [描述]` — 例如:`[输入]: 无序整数数组 A[1..n],n∈[1,10^6]`
|
|
121
|
-
2. **输出规格**:`[输出]: [描述]` — 例如:`[输出]: A 的升序排列`
|
|
122
|
-
3. **算法范式**:`[范式]: [分治/动规/贪心/回溯/随机化] 因为 [理由]`
|
|
123
|
-
4. **复杂度**:`[时间]: O([f(n)]) [空间]: O([g(n)]) [场景]: [最坏/平均]`
|
|
124
|
-
5. **正确性**:`[循环不变量/归纳策略]: [内容] ✅ 已证 / ❌ 未证`
|
|
125
|
-
6. **可行性**:`[类别]: [P/NP-hard/不可判定] [应对]: [精确/近似/启发式/重新表述]`
|
|
126
|
-
7. **改进建议**:`[优化方向]: [具体建议]`
|
|
127
|
-
8. **[GPU 可行性]**(若用于算法/算子设计)— 复杂度阶/并行度/访存/融合评估,标注友好/可改造/反模式 + 改造建议
|
|
128
|
-
|
|
129
|
-
**输出不得只给分析而无结论。**
|
|
130
|
-
|
|
131
|
-
## 与其他 skill 的关系 / Relations to Other Skills
|
|
132
|
-
|
|
133
|
-
- **优化思想**:梯度下降、分支定界等优化算法是算法思想的实例——优化关注最优值,算法关注达到最优值的步骤与代价。
|
|
134
|
-
- **变换思想**:FFT 是算法思想应用于变换的典范——O(n²)→O(n log n);变换把问题映到易解空间,算法在变换空间高效求解。
|
|
135
|
-
- **逻辑演绎**:正确性证明使用演绎推理(循环不变量、归纳)——算法正确性证明本质是一串演绎步骤。
|
|
136
|
-
- **归纳与类比**:分治用结构类比——子问题与原问题同构——正是归纳思想的算法化。
|
|
137
|
-
- **离散/组合思想**:算法处理离散对象,组合计数支撑复杂度分析——组合爆炸是算法思维要克服的核心障碍。
|
|
138
|
-
- **现代数学激活**:`../../references/books/matrix-analysis.md`(GEMM/低秩分解降阶)、`../../references/books/optimization-ml.md`(一阶/二阶法 GPU 可行性)、`../../references/books/abstract-algebra.md`(半环/有限域上的并行算法)。
|