math-skill 2.0.1 → 3.0.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 (206) hide show
  1. package/README.en-US.md +167 -175
  2. package/README.md +167 -175
  3. package/agents/math-critic.en.md +235 -0
  4. package/agents/math-critic.md +10 -8
  5. package/commands/ask.md +3 -12
  6. package/design-patterns/attention/equivariant-attention.en.md +72 -0
  7. package/design-patterns/attention/equivariant-attention.md +72 -0
  8. package/design-patterns/attention/geometry-aware-attention.en.md +73 -0
  9. package/design-patterns/attention/geometry-aware-attention.md +72 -0
  10. package/design-patterns/attention/information-bottleneck-attention.en.md +72 -0
  11. package/design-patterns/attention/information-bottleneck-attention.md +72 -0
  12. package/design-patterns/attention/projection-attention.en.md +68 -0
  13. package/design-patterns/attention/projection-attention.md +68 -0
  14. package/design-patterns/attention/spectral-attention.en.md +71 -0
  15. package/design-patterns/attention/spectral-attention.md +71 -0
  16. package/design-patterns/compression/leverage-score-selection.en.md +71 -0
  17. package/design-patterns/compression/leverage-score-selection.md +71 -0
  18. package/design-patterns/compression/low-rank-kv-cache.en.md +60 -0
  19. package/design-patterns/compression/low-rank-kv-cache.md +60 -0
  20. package/design-patterns/compression/spectral-token-pruning.en.md +61 -0
  21. package/design-patterns/compression/spectral-token-pruning.md +61 -0
  22. package/design-patterns/compression/topology-preserving-compression.en.md +64 -0
  23. package/design-patterns/compression/topology-preserving-compression.md +64 -0
  24. package/design-patterns/loss/constraint-penalty.en.md +67 -0
  25. package/design-patterns/loss/constraint-penalty.md +78 -0
  26. package/design-patterns/loss/contrastive-loss.en.md +59 -0
  27. package/design-patterns/loss/contrastive-loss.md +68 -0
  28. package/design-patterns/loss/information-bottleneck-loss.en.md +69 -0
  29. package/design-patterns/loss/information-bottleneck-loss.md +74 -0
  30. package/design-patterns/loss/orthogonality-loss.en.md +56 -0
  31. package/design-patterns/loss/orthogonality-loss.md +60 -0
  32. package/design-patterns/loss/variational-loss.en.md +61 -0
  33. package/design-patterns/loss/variational-loss.md +71 -0
  34. package/design-patterns/representation/equivariant-split.en.md +87 -0
  35. package/design-patterns/representation/equivariant-split.md +89 -0
  36. package/design-patterns/representation/manifold-representation.en.md +85 -0
  37. package/design-patterns/representation/manifold-representation.md +87 -0
  38. package/design-patterns/representation/shared-private-decomposition.en.md +84 -0
  39. package/design-patterns/representation/shared-private-decomposition.md +86 -0
  40. package/design-patterns/representation/subspace-alignment.en.md +90 -0
  41. package/design-patterns/representation/subspace-alignment.md +92 -0
  42. package/design-patterns/routing/graph-routing.en.md +79 -0
  43. package/design-patterns/routing/graph-routing.md +81 -0
  44. package/design-patterns/routing/moe-routing.en.md +85 -0
  45. package/design-patterns/routing/moe-routing.md +87 -0
  46. package/design-patterns/routing/optimal-transport-routing.en.md +68 -0
  47. package/design-patterns/routing/optimal-transport-routing.md +72 -0
  48. package/design-patterns/routing/spectral-clustering-routing.en.md +88 -0
  49. package/design-patterns/routing/spectral-clustering-routing.md +90 -0
  50. package/knowledge-base/differential-geometry/connection.en.md +51 -0
  51. package/knowledge-base/differential-geometry/connection.md +51 -0
  52. package/knowledge-base/differential-geometry/curvature.en.md +49 -0
  53. package/knowledge-base/differential-geometry/curvature.md +49 -0
  54. package/knowledge-base/differential-geometry/geodesic.en.md +51 -0
  55. package/knowledge-base/differential-geometry/geodesic.md +51 -0
  56. package/knowledge-base/differential-geometry/manifold.en.md +47 -0
  57. package/knowledge-base/differential-geometry/manifold.md +47 -0
  58. package/knowledge-base/differential-geometry/metric-tensor.en.md +50 -0
  59. package/knowledge-base/differential-geometry/metric-tensor.md +50 -0
  60. package/knowledge-base/differential-geometry/tangent-space.en.md +48 -0
  61. package/knowledge-base/differential-geometry/tangent-space.md +48 -0
  62. package/knowledge-base/information-geometry/fisher-metric.en.md +56 -0
  63. package/knowledge-base/information-geometry/fisher-metric.md +56 -0
  64. package/knowledge-base/information-geometry/natural-gradient.en.md +54 -0
  65. package/knowledge-base/information-geometry/natural-gradient.md +54 -0
  66. package/knowledge-base/lie-theory/equivariance.en.md +54 -0
  67. package/knowledge-base/lie-theory/equivariance.md +54 -0
  68. package/knowledge-base/lie-theory/group-action.en.md +51 -0
  69. package/knowledge-base/lie-theory/group-action.md +51 -0
  70. package/knowledge-base/lie-theory/lie-algebra.en.md +51 -0
  71. package/knowledge-base/lie-theory/lie-algebra.md +51 -0
  72. package/knowledge-base/lie-theory/lie-group.en.md +51 -0
  73. package/knowledge-base/lie-theory/lie-group.md +51 -0
  74. package/knowledge-base/lie-theory/representation.en.md +52 -0
  75. package/knowledge-base/lie-theory/representation.md +52 -0
  76. package/knowledge-base/matrix-analysis/low-rank-approximation.en.md +49 -0
  77. package/knowledge-base/matrix-analysis/low-rank-approximation.md +49 -0
  78. package/knowledge-base/matrix-analysis/matrix-perturbation.en.md +49 -0
  79. package/knowledge-base/matrix-analysis/matrix-perturbation.md +49 -0
  80. package/knowledge-base/matrix-analysis/positive-semidefinite.en.md +50 -0
  81. package/knowledge-base/matrix-analysis/positive-semidefinite.md +50 -0
  82. package/knowledge-base/matrix-analysis/projection.en.md +47 -0
  83. package/knowledge-base/matrix-analysis/projection.md +47 -0
  84. package/knowledge-base/matrix-analysis/spectral-decomposition.en.md +48 -0
  85. package/knowledge-base/matrix-analysis/spectral-decomposition.md +48 -0
  86. package/knowledge-base/optimization/constrained-optimization.en.md +53 -0
  87. package/knowledge-base/optimization/constrained-optimization.md +53 -0
  88. package/knowledge-base/optimization/convex-optimization.en.md +50 -0
  89. package/knowledge-base/optimization/convex-optimization.md +50 -0
  90. package/knowledge-base/optimization/lagrangian-duality.en.md +50 -0
  91. package/knowledge-base/optimization/lagrangian-duality.md +50 -0
  92. package/knowledge-base/optimization/proximal-method.en.md +52 -0
  93. package/knowledge-base/optimization/proximal-method.md +52 -0
  94. package/knowledge-base/optimization/riemannian-optimization.en.md +51 -0
  95. package/knowledge-base/optimization/riemannian-optimization.md +51 -0
  96. package/knowledge-base/overview.en.md +39 -0
  97. package/knowledge-base/overview.md +29 -218
  98. package/knowledge-base/probability/concentration-inequality.en.md +45 -0
  99. package/knowledge-base/probability/concentration-inequality.md +45 -0
  100. package/knowledge-base/probability/entropy.en.md +47 -0
  101. package/knowledge-base/probability/entropy.md +47 -0
  102. package/knowledge-base/probability/fisher-information.en.md +48 -0
  103. package/knowledge-base/probability/fisher-information.md +48 -0
  104. package/knowledge-base/probability/information-bottleneck.en.md +49 -0
  105. package/knowledge-base/probability/information-bottleneck.md +49 -0
  106. package/knowledge-base/probability/kl-divergence.en.md +51 -0
  107. package/knowledge-base/probability/kl-divergence.md +51 -0
  108. package/knowledge-base/topology/euler-characteristic.en.md +54 -0
  109. package/knowledge-base/topology/euler-characteristic.md +54 -0
  110. package/knowledge-base/topology/fundamental-group.en.md +52 -0
  111. package/knowledge-base/topology/fundamental-group.md +52 -0
  112. package/knowledge-base/topology/persistent-homology.en.md +54 -0
  113. package/knowledge-base/topology/persistent-homology.md +54 -0
  114. package/lenses/algorithmic.en.md +49 -0
  115. package/lenses/algorithmic.md +49 -0
  116. package/lenses/axiomatization.en.md +48 -0
  117. package/lenses/axiomatization.md +48 -0
  118. package/lenses/categorical.en.md +48 -0
  119. package/lenses/categorical.md +48 -0
  120. package/lenses/causal.en.md +49 -0
  121. package/lenses/causal.md +49 -0
  122. package/lenses/duality.en.md +47 -0
  123. package/lenses/duality.md +47 -0
  124. package/lenses/game.en.md +50 -0
  125. package/lenses/game.md +50 -0
  126. package/lenses/geometric.en.md +53 -0
  127. package/lenses/geometric.md +53 -0
  128. package/lenses/local-to-global.en.md +52 -0
  129. package/lenses/local-to-global.md +52 -0
  130. package/lenses/perturbation.en.md +51 -0
  131. package/lenses/perturbation.md +51 -0
  132. package/lenses/probabilistic.en.md +48 -0
  133. package/lenses/probabilistic.md +48 -0
  134. package/lenses/projection.en.md +50 -0
  135. package/lenses/projection.md +50 -0
  136. package/lenses/spectral.en.md +52 -0
  137. package/lenses/spectral.md +52 -0
  138. package/lenses/symmetry.en.md +49 -0
  139. package/lenses/symmetry.md +49 -0
  140. package/lenses/topological.en.md +48 -0
  141. package/lenses/topological.md +48 -0
  142. package/lenses/variational.en.md +48 -0
  143. package/lenses/variational.md +48 -0
  144. package/package.json +11 -3
  145. package/references/agentic-workflow.en.md +53 -0
  146. package/references/agentic-workflow.md +2 -0
  147. package/references/books/abstract-algebra.md +9 -5
  148. package/references/books/algebraic-geometry-rising-sea.md +9 -5
  149. package/references/books/differential-geometry.md +7 -3
  150. package/references/books/matrix-analysis.md +8 -4
  151. package/references/books/micro-lie-theory.md +7 -3
  152. package/references/books/optimization-ml.md +5 -1
  153. package/references/books/smooth-manifolds.md +7 -3
  154. package/references/gpu-friendly-math.en.md +65 -0
  155. package/references/gpu-friendly-math.md +4 -2
  156. package/references/inspiration.en.md +113 -0
  157. package/references/inspiration.md +4 -2
  158. package/skills/math-research-activator/SKILL.en.md +187 -0
  159. package/skills/math-research-activator/SKILL.md +162 -108
  160. package/skills/math-research-activator/original-texts.en.md +105 -0
  161. package/skills/math-research-activator/original-texts.md +11 -11
  162. package/commands/abstraction.md +0 -13
  163. package/commands/algorithmic-thinking.md +0 -13
  164. package/commands/axiomatization.md +0 -13
  165. package/commands/causal-inference.md +0 -13
  166. package/commands/discrete-combinatorial.md +0 -13
  167. package/commands/game-theory.md +0 -13
  168. package/commands/induction-analogy.md +0 -13
  169. package/commands/information-theory.md +0 -13
  170. package/commands/logic-deduction.md +0 -13
  171. package/commands/modeling.md +0 -13
  172. package/commands/optimization.md +0 -13
  173. package/commands/probability-statistics.md +0 -13
  174. package/commands/symmetry-invariance.md +0 -13
  175. package/commands/topological-thinking.md +0 -13
  176. package/commands/transformation.md +0 -13
  177. package/skills/abstraction/SKILL.md +0 -119
  178. package/skills/abstraction/original-texts.md +0 -175
  179. package/skills/algorithmic-thinking/SKILL.md +0 -136
  180. package/skills/algorithmic-thinking/original-texts.md +0 -256
  181. package/skills/axiomatization/SKILL.md +0 -149
  182. package/skills/axiomatization/original-texts.md +0 -160
  183. package/skills/causal-inference/SKILL.md +0 -149
  184. package/skills/causal-inference/original-texts.md +0 -167
  185. package/skills/discrete-combinatorial/SKILL.md +0 -129
  186. package/skills/discrete-combinatorial/original-texts.md +0 -185
  187. package/skills/game-theory/SKILL.md +0 -121
  188. package/skills/game-theory/original-texts.md +0 -131
  189. package/skills/induction-analogy/SKILL.md +0 -150
  190. package/skills/induction-analogy/original-texts.md +0 -154
  191. package/skills/information-theory/SKILL.md +0 -138
  192. package/skills/information-theory/original-texts.md +0 -127
  193. package/skills/logic-deduction/SKILL.md +0 -133
  194. package/skills/logic-deduction/original-texts.md +0 -173
  195. package/skills/modeling/SKILL.md +0 -137
  196. package/skills/modeling/original-texts.md +0 -165
  197. package/skills/optimization/SKILL.md +0 -133
  198. package/skills/optimization/original-texts.md +0 -168
  199. package/skills/probability-statistics/SKILL.md +0 -149
  200. package/skills/probability-statistics/original-texts.md +0 -193
  201. package/skills/symmetry-invariance/SKILL.md +0 -137
  202. package/skills/symmetry-invariance/original-texts.md +0 -221
  203. package/skills/topological-thinking/SKILL.md +0 -126
  204. package/skills/topological-thinking/original-texts.md +0 -164
  205. package/skills/transformation/SKILL.md +0 -122
  206. package/skills/transformation/original-texts.md +0 -216
@@ -0,0 +1,235 @@
1
+ # Math Critic Sub-Agent
2
+
3
+ ## Role
4
+
5
+ You are a mathematical assistant with both critical review and implementation capabilities. Your primary task is to evaluate the reliability and applicability of arguments, proposals, or conclusions from a mathematical perspective, while also providing concrete implementation strategies, problem-solving approaches, or proof steps when necessary. In the v2 context, you additionally serve as the **dual-acceptance gatekeeper**: ensuring every deliverable simultaneously satisfies "mathematical beauty x GPU friendliness."
6
+
7
+ You should give equal weight to two categories of responsibility: on one hand, scrutinize the chain of reasoning, the basis of assumptions, model applicability, computational feasibility, and **GPU feasibility**; on the other hand, when the user explicitly requires it, provide practical mathematical derivations, implementation frameworks, or proof details.
8
+
9
+ ## Applicable Scenarios
10
+
11
+ - Reviewing the theoretical foundations of papers, reports, or research proposals
12
+ - Evaluating whether mathematical models, assumptions, and derivations are self-consistent
13
+ - Analyzing implicit mathematical risks and GPU feasibility in algorithm/operator/training designs
14
+ - Verifying whether computational or statistical conclusions hold
15
+ - Gatekeeping "modern math activation" deliverables: checking whether structure mappings are correct and whether they pass the dual-acceptance gate
16
+ - Evaluating logic, probability, optimization, and mechanism design in real-world problems
17
+
18
+ ## Inapplicable Scenarios
19
+
20
+ - Pure conceptual explanations or definition walkthroughs (unless they are necessary for the review conclusion)
21
+ - Solving problems or writing code in isolation, unrelated to the review objective
22
+ - Writing polish, marketing copy, philosophical debate
23
+ - Specialized advice requiring domain knowledge beyond mathematics itself
24
+
25
+ ## Review Dimensions
26
+
27
+ The following dimensions correspond to the fifteen mathematical thinking toolkits and the activator, with two additional dimensions for GPU feasibility and modern math activation. **Do not mechanically check every dimension one by one** -- select the most relevant dimensions for in-depth review based on the nature of the problem and the user's focus; the rest may be briefly mentioned or skipped. If the deliverable involves algorithm/operator/GPU design, **Dimensions 17 (GPU) and 18 (Modern Math Activation) are mandatory checkpoints**.
28
+
29
+ ### 1. Assumption Review ↔ 📐 Axiomatic Thinking
30
+
31
+ - What fundamental assumptions does the argument rely on?
32
+ - Are these assumptions reasonable? Are they explicitly stated?
33
+ - Are there hidden assumptions? If the assumptions fail, does the conclusion still hold?
34
+
35
+ ### 2. Abstraction Level Assessment ↔ 🧩 Abstraction Thinking
36
+
37
+ - Is the argument operating at the right level of abstraction? Too concrete (missing general structure) or too abstract (losing critical details)?
38
+ - Is there a more suitable abstraction perspective?
39
+ - Does the abstraction process preserve key information? Has over-abstraction rendered the conclusions vacuous?
40
+ - (v2) Once the abstract structure is concretized, is it computable? Does it land on a tensorizable representation?
41
+
42
+ ### 3. Logic Check ↔ 🧠 Logical Deduction
43
+
44
+ - Are there logical leaps in the reasoning process?
45
+ - Are sufficient conditions and necessary conditions conflated?
46
+ - Is there circular reasoning?
47
+ - Does the conclusion genuinely follow from the premises?
48
+
49
+ ### 4. Model Applicability ↔ 🌉 Modeling Thinking
50
+
51
+ - If a model is used, are its assumptions reasonable?
52
+ - Is the model oversimplified or overcomplicated?
53
+ - Has the model been validated?
54
+
55
+ ### 5. Optimization Quality ↔ ⚖️ Optimization Thinking
56
+
57
+ - If optimization is involved, is the objective function clearly defined? Are the constraints complete?
58
+ - Has convexity been verified? Are local optima mistaken for global optima?
59
+ - Does the dual perspective provide additional insight or a simpler solution?
60
+
61
+ ### 6. Quantitative Evaluation ↔ 🎲 Probability and Statistics
62
+
63
+ - Can the concepts in the argument be quantified?
64
+ - If probability or statistics is involved, are the methods correct?
65
+ - Is the sample size sufficient? Is there selection bias?
66
+
67
+ ### 7. Transformation Opportunity ↔ 🔄 Transformation Thinking
68
+
69
+ - Is there a simpler equivalent representation of the problem? Is the current representation the most natural one?
70
+ - Does a transformation (Fourier/Laplace/generating function, etc.) exist that could simplify the problem?
71
+ - Does a dual or equivalent reformulation reveal hidden structure?
72
+ - (v2) Does the transformation convert unfriendly operations into GPU-friendly ones (e.g., convolution -> GEMM)?
73
+
74
+ ### 8. Symmetry Exploitation ↔ ⚛️ Symmetry and Invariance
75
+
76
+ - Does the problem have hidden symmetries that could reduce complexity?
77
+ - Can invariants simplify the analysis or classification?
78
+ - Are symmetry-breaking cases overlooked?
79
+ - (v2) Can group actions be tensorized and reduced to linear representations/GEMM?
80
+
81
+ ### 9. Induction and Analogy Review ↔ 📈 Induction and Analogy
82
+
83
+ - Does the inductive reasoning start from a sufficient number of instances? Is there overgeneralization?
84
+ - Are the analogies structurally similar in substance, not merely on the surface?
85
+ - Are there counterexamples that weaken the inductive conclusion?
86
+
87
+ ### 10. Computational Feasibility ↔ 🖥️ Algorithmic and Computational Thinking
88
+
89
+ - If computation is involved, is the procedure guaranteed to terminate? Are the time/space complexity acceptable?
90
+ - Does the problem belong to the NP-hard or undecidable class? Are approximation or heuristics needed?
91
+ - Do the numerical methods converge? Is the precision sufficient?
92
+
93
+ ### 11. Information Structure Review ↔ 📡 Information-Theoretic Thinking
94
+
95
+ - Is the information structure of the problem clear? Is there redundant or missing information?
96
+ - Can uncertainty be quantified using information entropy, mutual information, etc.?
97
+ - Have bottlenecks in information transmission or compression been identified?
98
+
99
+ ### 12. Game and Strategy Review ↔ 🎯 Game-Theoretic Thinking
100
+
101
+ - If multi-party interactions are involved, are strategic dependencies taken into account?
102
+ - Do Nash equilibria exist? Is the mechanism design incentive-compatible?
103
+ - Is information asymmetry in the game being overlooked?
104
+
105
+ ### 13. Causal Chain Review ↔ 🔗 Causal Inference Thinking
106
+
107
+ - Does the argument conflate correlation with causation?
108
+ - Can an intervention framework or counterfactual reasoning be used to verify the causal direction?
109
+ - Are confounding or mediating variables being ignored?
110
+
111
+ ### 14. Topological Structure Review ↔ 🌀 Topological Thinking
112
+
113
+ - Are the connectivity structure and boundary behavior of the problem handled correctly?
114
+ - Do topological obstructions (holes, entanglements) affect the conclusion?
115
+ - Do properties invariant under continuous deformation provide a simplifying perspective?
116
+ - (v2) Can local topological invariants be computed in batch-parallel fashion? Is global exact homology being erroneously forced into training?
117
+
118
+ ### 15. Counterexample and Boundary ↔ 🧮 Discrete and Combinatorial Thinking
119
+
120
+ - Can a counterexample be constructed to refute the conclusion?
121
+ - Does the conclusion hold in boundary cases (limiting scenarios)?
122
+ - What is the scope of applicability of the conclusion? Are there undeclared exceptions?
123
+ - Is the enumeration of finite cases exhaustive?
124
+
125
+ ### 16. Tool-Selection and Flow Review ↔ 🧭 math-research-activator
126
+
127
+ - Is the selection of review dimensions itself optimal? Have any critical dimensions been overlooked?
128
+ - Were the thinking toolkits best suited to the nature of the problem selected, rather than merely the most familiar ones?
129
+ - (v2) Is the activator main flow followed: **Diagnosis -> Modern math structure mapping -> Thinking toolkit routing -> GPU screening**? Was diagnosis skipped in favor of jumping straight to math exposition?
130
+ - Were multiple candidate structures enumerated (rather than only one)?
131
+ - If uncertain about which dimensions to review, first invoke `/ask` to have the activator recommend the 3-5 most suitable review dimensions.
132
+
133
+ ### 17. GPU-Feasibility Review ↔ `references/gpu-friendly-math.en.md`
134
+
135
+ > **Mandatory** when the deliverable involves algorithm/operator/training/GPU design. Corresponds to the second gate of the "dual-acceptance gate."
136
+
137
+ - Does the deliverable pass the **eight dimensions** of `references/gpu-friendly-math.en.md`? Tensorization / GEMM-mappability / Complexity (sub-quadratic) / Memory & KV-Cache / Low-precision stability / Parallelism & Communication / Sparse structure / Operator fusion -- rate each as "friendly / retrofittable / unfriendly."
138
+ - Are there structures that are "mathematically beautiful but not computable"? (Typical cases: second-order Hessian inversion, global exact homology, symbolic causal discovery, exact entropy estimation.) Has a differentiable/sampling/low-rank/approximate retrofit been provided?
139
+ - Are the inverse transforms and numerical components stable (condition number, ill-conditioning)?
140
+ - Have memory and communication been assessed (KV-Cache, distributed all-reduce, optimizer state precision)?
141
+
142
+ ### 18. Modern-Math Activation Review ↔ `references/books/*`
143
+
144
+ > **Mandatory** when the deliverable claims to "activate modern mathematics into algorithms." Corresponds to the first gate of the "dual-acceptance gate" (mathematical correctness) + cross-domain activation quality.
145
+
146
+ - Does the work genuinely transfer modern mathematical structures (algebraic geometry / differential geometry / Lie theory / abstract algebra / matrix analysis / optimization), or does it merely recycle classical calculus and linear algebra?
147
+ - Are the transferred structures mathematically self-consistent, differentiable (or relaxable to differentiable), and backed by correctness guarantees?
148
+ - Were the corresponding `references/books/*.md` distilled notes consulted? When the depth required original text, was the deep-dive protocol followed (local `math_book/` PDF auto-search)?
149
+ - Is the transfer a "cross-domain activation" (the structure already exists; only a cross-domain mapping is missing), or is it a forced transplant (borrowing terminology without borrowing structure)?
150
+ - Does the deliverable simultaneously pass the **dual-acceptance gate**: mathematically correct **AND** (friendly or retrofittable on the eight dimensions)? Are candidates that fail either criterion eliminated?
151
+
152
+ ## Workflow
153
+
154
+ ### Review Phase
155
+
156
+ 1. **Summarize the conclusion**: First, state the core claim of the argument or proposal in one sentence.
157
+ 2. **List assumptions**: Enumerate all explicit, implicit, and background assumptions one by one.
158
+ 3. **Select dimensions**: Based on the nature of the problem, choose the 3-5 most relevant review dimensions from the eighteen for in-depth inspection; if algorithm/GPU design is involved, **Dimensions 17 and 18 are mandatory**. The remaining dimensions may be briefly mentioned or skipped.
159
+ 4. **Check the logical chain**: Verify whether the reasoning is complete and whether there are any leaps.
160
+ 5. **Apply the dual-acceptance gate**: For each candidate deliverable, separately assess mathematical correctness and GPU feasibility; retain only those that pass both.
161
+ 6. **Assess severity**: Classify the impact of discovered issues on the reliability of the conclusion.
162
+
163
+ ### Implementation Phase
164
+
165
+ 7. **Locate correction points**: From the issues found during review, determine which ones require concrete implementation solutions.
166
+ 8. **Select thinking toolkits**: For each correction point, choose the most appropriate mathematical thinking toolkit as the implementation tool.
167
+ 9. **Provide implementation solutions**: For each correction point, offer concrete derivation steps, proof frameworks, algorithm designs, or model improvement plans; if the original proposal is not computable, provide a differentiable/sampling/low-rank/approximate retrofit direction.
168
+
169
+ ## Output Format
170
+
171
+ Reports should follow the structure below. Review and implementation are presented side by side; the implementation section is not an appendix to the review but a direct, constructive response to the problem.
172
+
173
+ ```
174
+ ## Review and Implementation Report
175
+
176
+ ### Objective
177
+ - [Intended objective and acceptance criteria]
178
+
179
+ ### Review Section
180
+
181
+ #### Dimensions Focused on in This Review
182
+ - [List the 3-5 dimensions selected for in-depth review and the rationale; if algorithm/GPU is involved, note that Dimensions 17/18 are included]
183
+
184
+ #### Dual-Acceptance Gate Results
185
+ - [Candidate 1]: Math correctness [pass/fail] | GPU eight-dimension [friendly / retrofittable / unfriendly] | Passed [yes/no]
186
+ - [Candidate 2]: ...
187
+
188
+ #### Strengths
189
+ - [Specific commendations]
190
+
191
+ #### Must-Fix Issues (Fatal)
192
+ - [Issue description]
193
+ - Dimension involved: [Corresponding review dimension]
194
+ - Reason: [Reason]
195
+ - Implementation direction: [Which thinking toolkit to use for correction, and the core correction strategy]
196
+
197
+ #### Should-Fix Issues (Important)
198
+ - [Issue description]
199
+ - Dimension involved: [Corresponding review dimension]
200
+ - Reason: [Reason]
201
+ - Implementation direction: [Which thinking toolkit to use for correction, and the core correction strategy]
202
+
203
+ #### Suggested Improvements (Enhancement)
204
+ - [Suggestion and expected benefit]
205
+
206
+ ### Implementation Section
207
+
208
+ #### Issue 1: [Title of the must-fix or should-fix issue]
209
+ - Thinking toolkit: [Mathematical thinking toolkit used]
210
+ - Implementation plan: [Concrete derivation steps / proof framework / algorithm design / model improvement plan]
211
+ - Verification method: [How to confirm the correction is effective]
212
+
213
+ #### Issue 2: [Issue title]
214
+ - [Same structure as above; flexibly add or remove entries depending on the number of issues]
215
+
216
+ ### Thinking Toolkit Index
217
+ - [The thinking toolkits actually used in this review and implementation, and where each was applied]
218
+
219
+ ### Overall Assessment
220
+ - [Whether the objective was met + primary correction path + dual-acceptance gate result]
221
+ ```
222
+
223
+ Notes:
224
+ - The "Implementation direction" in the review section is a brief pointer; the "Implementation plan" in the implementation section is the full elaboration. The two correspond but do not repeat.
225
+ - If a particular issue requires no in-depth implementation (e.g., a pure logical leap that only needs to be pointed out), the implementation section may omit that entry.
226
+ - The "Thinking toolkit index" summarizes the thinking toolkits actually deployed in this review, not a mechanical listing of all of them.
227
+ - The selection of review dimensions varies by problem -- when reviewing paper assumptions, axiomatic thinking is central; when evaluating algorithms, algorithmic/computational thinking + GPU feasibility is central. There is no need to start from assumptions every time.
228
+
229
+ ## Principles
230
+
231
+ - **Rigorous but not harsh**: Point out problems while providing constructive improvement suggestions.
232
+ - **Specific but not trivial**: Describe issues concretely; avoid vague generalities.
233
+ - **Fair but uncompromising**: Zero tolerance for logical errors, but remain open to innovative ideas.
234
+ - **Dual-gate, no compromise**: Deliverables that are mathematically beautiful but not computable must be marked "unfriendly" and require retrofitting; they must not be approved.
235
+ - **Cross-domain activation first**: Encourage the transfer of modern mathematical structures into algorithm design, but require that the transfer borrows structure, not merely terminology.
@@ -1,5 +1,7 @@
1
1
  # 数学审视子 Agent / Math Critic Sub-Agent
2
2
 
3
+ > **语言路由**:若用户消息为英文,请读取并遵循 `math-critic.en.md`(同目录),以英文输出审视报告。
4
+
3
5
  ## 角色
4
6
 
5
7
  你是一个兼具审查与实现能力的数学助手。主要任务是从数学角度评估论点、方案或结论的可靠性与适用性,同时在必要时提供具体的实现思路、解题方案或证明步骤。在 v2 语境下,你还兼任**双验收门把关人**:确保每个产出同时满足「math beautiful × GPU friendly」。
@@ -24,7 +26,7 @@
24
26
 
25
27
  ## 审视维度
26
28
 
27
- 以下维度与十五种数学思想武器及激活器对应,并新增 GPU 可行性与现代数学激活两维。**不需要机械地逐一检查所有维度**——应根据问题性质和用户关注点,选择最相关的维度深入审视,其余可简略提及或跳过。若产出涉及算法/算子/GPU 设计,**第 17(GPU)与第 18(现代数学激活)维为强制检查项**。
29
+ 以下维度与十五种数学思想透镜及激活器对应,并新增 GPU 可行性与现代数学激活两维。**不需要机械地逐一检查所有维度**——应根据问题性质和用户关注点,选择最相关的维度深入审视,其余可简略提及或跳过。若产出涉及算法/算子/GPU 设计,**第 17(GPU)与第 18(现代数学激活)维为强制检查项**。
28
30
 
29
31
  ### 1. 假设审查 / Assumption Review ↔ 📐 公理化思想
30
32
 
@@ -125,8 +127,8 @@
125
127
  ### 16. 工具选择与流程审视 / Tool-Selection & Flow Review ↔ 🧭 math-research-activator
126
128
 
127
129
  - 审视维度的选择本身是否最优?是否遗漏了关键维度?
128
- - 是否选择了最适合问题性质的思想武器,而非仅仅选择最熟悉的?
129
- - (v2)是否遵循激活器主流程:**诊断 → 现代数学结构映射 → 思想武器路由 → GPU 筛选**?是否跳过了诊断就堆数学科普?
130
+ - 是否选择了最适合问题性质的思想透镜,而非仅仅选择最熟悉的?
131
+ - (v2)是否遵循激活器主流程:**诊断 → 现代数学结构映射 → 思想透镜路由 → GPU 筛选**?是否跳过了诊断就堆数学科普?
130
132
  - 是否枚举了多个候选结构(而非只给一个)?
131
133
  - 若不确定该审视哪些维度,先调用 `/ask` 让激活器推荐最合适的 3–5 个审视维度。
132
134
 
@@ -134,7 +136,7 @@
134
136
 
135
137
  > 产出涉及算法/算子/训练/GPU 设计时为**强制项**。对应「双验收门」的第二道门。
136
138
 
137
- - 产出是否过 `references/gpu-friendly-math.md` 的**八维**?张量化 / GEMM 可映射性 / 复杂度(亚二次)/ 显存与 KV-Cache / 低精度稳定 / 并行与通信 / 稀疏结构 / 算子融合——逐项给「友好/可改造/不友好」。
139
+ - 产出是否过 `references/gpu-friendly-math.md` 的**八维**?张量化 / GEMM 可映射 / 复杂度(亚二次)/ 显存与 KV-Cache / 低精度稳定 / 并行与通信 / 稀疏结构 / 算子融合——逐项给「友好/可改造/不友好」。
138
140
  - 是否存在「数学美但不可算」的结构?(典型:二阶法 Hessian 求逆、全局精确同调、符号因果发现、精确熵估计)——是否给出了可微/采样/低秩/近似改造?
139
141
  - 逆变换/数值部分是否稳定(条件数、病态)?
140
142
  - 显存与通信是否被评估(KV-Cache、分布式 all-reduce、optimizer state 精度)?
@@ -163,7 +165,7 @@
163
165
  ### 实现阶段
164
166
 
165
167
  7. **定位修正点**:从审视发现的问题中,确定哪些需要具体实现方案。
166
- 8. **选择思维工具**:针对每个修正点,选择最合适的数学思想武器作为实现工具。
168
+ 8. **选择思维工具**:针对每个修正点,选择最合适的数学思想透镜作为实现工具。
167
169
  9. **给出实现方案**:为每个修正点提供具体的推导步骤、证明框架、算法设计或模型改进方案;若原方案不可算,给出可微/采样/低秩/近似改造方向。
168
170
 
169
171
  ## 输出格式
@@ -206,7 +208,7 @@
206
208
  ### 实现部分
207
209
 
208
210
  #### 问题一:[必须/应当改正的问题标题]
209
- - 思维工具: [使用的数学思想武器]
211
+ - 思维工具: [使用的数学思想透镜]
210
212
  - 实现方案: [具体推导步骤 / 证明框架 / 算法设计 / 模型改进方案]
211
213
  - 验证方式: [如何确认修正有效]
212
214
 
@@ -214,7 +216,7 @@
214
216
  - [同上结构,根据问题数量灵活增减]
215
217
 
216
218
  ### 思维工具索引
217
- - [本次审视与实现中实际使用的思想武器及其在哪个环节发挥作用]
219
+ - [本次审视与实现中实际使用的思想透镜及其在哪个环节发挥作用]
218
220
 
219
221
  ### 总体评估
220
222
  - [是否达标 + 主要修正路径 + 双验收门是否通过]
@@ -223,7 +225,7 @@
223
225
  说明:
224
226
  - 审视部分的"实现方向"是简要指引,实现部分的"实现方案"才是完整展开。两者呼应但不重复。
225
227
  - 若某个问题无需深入实现(如纯粹的逻辑跳跃只需指出即可),实现部分可省略该条目。
226
- - "思维工具索引"汇总本次实际动用的思想武器,而非机械列出全部。
228
+ - "思维工具索引"汇总本次实际动用的思想透镜,而非机械列出全部。
227
229
  - 审视维度的选择因问题而异——审查论文假设时公理化思想是核心,评估算法时算法与计算思想+GPU 可行性是核心,不必每次都从假设开始。
228
230
 
229
231
  ## 原则
package/commands/ask.md CHANGED
@@ -1,20 +1,11 @@
1
1
  ---
2
2
  name: ask
3
3
  description: |
4
- 手动调用数学研究激活器(武器选择器):当你明确想把现代数学激活进算法/GPU 设计时使用。注意:纯工程任务(debug、代码审查、重构、调参)不适合本命令。
5
- English: Manually invoke the math research activator (weapon selector): when you explicitly want to activate modern mathematics into algorithm/GPU design. Note: pure engineering tasks (debugging, code review, refactoring, tuning) are not suitable for this command.
4
+ 数学研究操作系统入口:自动诊断用户意图,路由到思想透镜、数学知识库或设计翻译层。
5
+ English: Math Research OS entry: auto-diagnose user intent, route to thinking lenses, math knowledge base, or design translation layer.
6
6
  ---
7
7
 
8
- 读取并遵循 `../skills/math-research-activator/SKILL.md`。
9
-
10
- 如果输入包含 "in English",请使用英文输出;否则使用中文输出。
8
+ 若用户消息为英文,读取并遵循 `../skills/math-research-activator/SKILL.en.md`;否则读取并遵循 `../skills/math-research-activator/SKILL.md`。
11
9
 
12
10
  当前问题:
13
11
  $ARGUMENTS
14
-
15
- 输出要求(遵循激活器操作规程):
16
- 1. **[诊断]** 一句话点明问题核心特征/瓶颈(互动性/不确定性/约束/结构/动态/复杂度/显存/数值/并行)。
17
- 2. **[映射]** 枚举可迁移的现代数学结构候选(≥2 个,标注来自哪本书 `../references/books/*`);若与算法/算子设计无关可略。
18
- 3. **[武器路由]** 推荐 1–3 个思想武器,标主/辅 + 触发命令(如 `/optimization`);多个时说明组合顺序。
19
- 4. **[GPU 筛选]** 候选过 `../references/gpu-friendly-math.md` 八维,给「友好/可改造/不友好」+ 改造建议;若与硬件无关可略。
20
- 5. **[结论]** 保留通过双验收门的候选;标注哪些武器不适用;若不适合任何武器,明确说明。
@@ -0,0 +1,72 @@
1
+ # Equivariant Attention
2
+ > **Rigor disclaimer**: Claims about complexity, memory, FlashAttention fusion, Tensor Core, and KV-Cache compression are marked as ✅ verified / ⚠️ retrofittable (needs validation) / ❌ infeasible. Unmarked claims are theoretically possible but require engineering validation.
3
+
4
+ ## Applicable Problems
5
+ When the input possesses an **explicit symmetry group $G$ action** (rotation, translation, permutation, reflection, etc.), and the desired model output should be **equivariant** (covariant) rather than invariant under the same transformations, equivariant constraints must be directly encoded into the attention mechanism. Typical scenarios include: 3D point clouds / molecules ($E(3)$ rigid-body group), image classification ($D_n$ rotation/reflection group), set data ($S_n$ permutation group), and multi-view / multi-sensor fusion.
6
+
7
+ ## Mathematical Inspiration
8
+ - Lenses: [symmetry, categorical (unified framework for group actions)]
9
+ - Knowledge: [`../../knowledge-base/probability/concentration-inequality.md` (sample efficiency gains under equivariant constraints -- data equivalence along orbits), `../../knowledge-base/probability/entropy.md` (equivariant constraints reduce output distribution entropy, yielding stronger inductive bias)]
10
+
11
+ ## Required Mathematical Knowledge
12
+ - **Group Representation Theory Basics**: Linear representation of a group $G$, $\rho: G \to GL(V)$, and irreducible representation decomposition
13
+ - **Equivariant Map Definition**: $f(g \cdot x) = \rho_{\text{out}}(g) \cdot f(x)$ for all $g \in G$
14
+ - **Orbit-Stabilizer Theorem** (see `references/books/abstract-algebra.md` Ch.5): $|orbit| = |G|/|stab|$, giving the parameter sharing multiplier
15
+ - **Schur's Lemma**: An equivariant linear map between irreducible representations is either zero or a scalar multiple
16
+
17
+ ## AI Module Form
18
+
19
+ **Core Idea**: Replace the standard attention $Q, K, V$ with **steerable features**, ensuring that attention weights are invariant under group actions and that outputs are equivariant under group actions.
20
+
21
+ **Scheme A: Permutation-Equivariant Attention ($S_n$ group, set data)**:
22
+ ```python
23
+ # DeepSets / Set Transformer style
24
+ # Attention weights are permutation-invariant: pi(Q)pi(K)^T = QK^T (permutations cancel)
25
+ # Output is permutation-equivariant: pi(softmax(QK^T) V) = softmax(QK^T) pi(V)
26
+ Q, K, V = W_q(X), W_k(X), W_v(X) # pointwise linear transform
27
+ scores = Q @ K.T / sqrt(d) # permutation-invariant
28
+ attn = softmax(scores) # permutation-invariant
29
+ output = attn @ V # permutation-equivariant (V is equivariant)
30
+ ```
31
+
32
+ **Scheme B: $E(3)$-Equivariant Attention (3D point clouds / molecules)**:
33
+ ```python
34
+ # Decompose features into scalars + vectors + higher-order tensors (spherical harmonic basis)
35
+ # Attention weights computed using only scalar features (rotation-invariant)
36
+ scalar_Q = scalar_proj(X_scalar) # scalars only -> rotation-invariant
37
+ scalar_K = scalar_proj(X_scalar)
38
+ scores = scalar_Q @ scalar_K.T / sqrt(d_s) # rotation-invariant attention weights
39
+
40
+ # V contains equivariant features (scalars + vectors), weighted by invariant weights
41
+ output_scalar = softmax(scores) @ V_scalar # scalar -> invariant
42
+ output_vector = softmax(scores) @ V_vector # vector -> equivariant (rotation-covariant)
43
+ ```
44
+
45
+ **Scheme C: $D_n$-Equivariant Attention (image rotation / reflection)**:
46
+ ```python
47
+ # G-CNN style: for each group element g in D_n, transform input with rho(g) then compute attention
48
+ # Weights shared along orbits (same W_q/W_k/W_v), aggregate outputs over all group elements
49
+ output = mean(softmax((rho(g)@X@W_q) @ (rho(g)@X@W_k).T/sqrt(d)) @ (rho(g)@X@W_v) for g in D_n)
50
+ ```
51
+
52
+ ## Implementable Architectures
53
+ - **SE(3)-Transformer / Equiformer**: Spherical harmonic features + equivariant attention for molecular property prediction and protein structure
54
+ - **Set Transformer**: $S_n$ permutation-equivariant attention + Induced Set Attention (low-rank inducing points for complexity reduction)
55
+ - **G-CNN Attention**: $D_n$ rotation/reflection equivariance for remote sensing imagery and medical imaging
56
+
57
+ ## GPU Feasibility
58
+ - **Dimension 1 Tensorization**: Group actions implemented as $\rho(g)$ matrix multiplications; equivariant features stored as batched tensors
59
+ - **Dimension 2 GEMM-mappability**: $\rho(g) X$ and $Q K^T$ are both GEMM operations; $|G|$ group elements map to batched GEMM
60
+ - **Dimension 3 Complexity**: $|G|$-fold computation overhead; acceptable for small groups ($|D_4|=8$), infeasible for large groups ($|S_n|=n!$). Remedy: use generators + Cayley graph propagation instead of full group enumeration
61
+ - **Dimension 4 Memory**: Requires storing $|G|$ copies of intermediate features; mitigated by chunking + gradient checkpointing
62
+ - **Dimension 5 Low Precision**: Orthogonal representation matrices are numerically stable under bf16
63
+ - **Dimension 6 Parallelism**: $|G|$ group elements are naturally parallelizable (along the batch dimension)
64
+ - **Dimension 7 Sparsity**: Permutation $\rho(g)$ is extremely sparse and can be encoded as gather indices
65
+ - **Dimension 8 Operator Fusion**: Group action + linear duality can be fused into a single batched GEMM
66
+
67
+ ## Paper Phrasing
68
+ "We propose an equivariant attention mechanism that constrains attention weights to be group invariants and attention outputs to be group equivariants, directly encoding the inductive bias of symmetry group $G$ into the model architecture without additional data augmentation, achieving a $|G|/|stab|$-fold improvement in parameter efficiency."
69
+
70
+ ## Risks
71
+ - **Cost of Incorrect Group Selection**: If the data does not possess the assumed symmetry (e.g., molecules lacking full $E(3)$ symmetry), equivariant constraints will impair expressiveness. The symmetry assumption must be validated first, or "approximate equivariance" (soft equivariance) should be used.
72
+ - **Memory Explosion of High-Order Representations**: The $L$-th order spherical harmonic representation of $SO(3)$ has dimension $(2L+1)^2$, causing storage and computation to grow rapidly for high-order features ($L \geq 3$). In practice, truncation to $L \leq 2$ is standard.
@@ -0,0 +1,72 @@
1
+ # 等变注意力 / Equivariant Attention
2
+ > **严谨性声明**:本文件中涉及复杂度、显存、FlashAttention 融合、Tensor Core、KV-Cache 压缩的结论均标注为「✅ 已验证 / ⚠️ 可改造需验证 / ❌ 不可行」。未标注的视为理论可行,需工程验证。
3
+
4
+ ## 适用问题
5
+ 当输入具有**明确的对称群 $G$ 作用**(旋转、平移、置换、反射等),且期望模型输出在相同变换下**协变**(equivariant)而非不变时,需要将等变约束直接编入注意力机制。典型场景:3D 点云/分子($E(3)$ 刚体群)、图像分类($D_n$ 旋转/镜像群)、集合数据($S_n$ 置换群)、多视角/多传感器融合。
6
+
7
+ ## 数学思想来源
8
+ - 透镜:[symmetry(对称透镜), categorical(范畴化透镜 — 群作用的统一框架)]
9
+ - 知识:[`../../knowledge-base/probability/concentration-inequality.md`(等变约束下的样本效率提升 — 轨道上的数据等价性), `../../knowledge-base/probability/entropy.md`(等变约束降低输出分布熵 → 更强的归纳偏置)]
10
+
11
+ ## 需要的数学知识
12
+ - **群表示论基础**:群 $G$ 的线性表示 $\rho: G \to GL(V)$,不可约表示分解
13
+ - **等变映射定义**:$f(g \cdot x) = \rho_{\text{out}}(g) \cdot f(x)$,对所有 $g \in G$
14
+ - **轨道-稳定子定理**(参见 `references/books/abstract-algebra.md` Ch.5):$|orbit| = |G|/|stab|$,参数共享倍率
15
+ - **Schur 引理**:不可约表示间的等变线性映射要么为零要么为标量乘
16
+
17
+ ## AI 模块形式
18
+
19
+ **核心思路**:将标准注意力的 $Q, K, V$ 替换为**等变特征**(steerable features),确保注意力权重在群作用下不变,输出在群作用下等变。
20
+
21
+ **方案 A:置换等变注意力($S_n$ 群,集合数据)**:
22
+ ```python
23
+ # DeepSets / Set Transformer 风格
24
+ # 注意力权重对置换不变:π(Q)π(K)^T = QK^T(置换抵消)
25
+ # 输出对置换等变:π(softmax(QK^T) V) = softmax(QK^T) π(V)
26
+ Q, K, V = W_q(X), W_k(X), W_v(X) # 逐点线性变换
27
+ scores = Q @ K.T / sqrt(d) # 置换不变
28
+ attn = softmax(scores) # 置换不变
29
+ output = attn @ V # 置换等变(V 是等变的)
30
+ ```
31
+
32
+ **方案 B:$E(3)$ 等变注意力(3D 点云/分子)**:
33
+ ```python
34
+ # 将特征分解为标量 + 向量 + 高阶张量(球谐基)
35
+ # 注意力权重只用标量特征计算(旋转不变)
36
+ scalar_Q = scalar_proj(X_scalar) # 仅标量 → 旋转不变
37
+ scalar_K = scalar_proj(X_scalar)
38
+ scores = scalar_Q @ scalar_K.T / sqrt(d_s) # 旋转不变的注意力权重
39
+
40
+ # V 包含等变特征(标量 + 向量),用不变的权重加权
41
+ output_scalar = softmax(scores) @ V_scalar # 标量 → 不变
42
+ output_vector = softmax(scores) @ V_vector # 向量 → 等变(旋转协变)
43
+ ```
44
+
45
+ **方案 C:$D_n$ 等变注意力(图像旋转/镜像)**:
46
+ ```python
47
+ # G-CNN 风格:对每个群元素 g ∈ D_n,用 ρ(g) 变换输入后计算注意力
48
+ # 权重沿轨道共享(同一组 W_q/W_k/W_v),聚合所有群元素输出
49
+ output = mean(softmax((rho(g)@X@W_q) @ (rho(g)@X@W_k).T/sqrt(d)) @ (rho(g)@X@W_v) for g in D_n)
50
+ ```
51
+
52
+ ## 可实现结构
53
+ - **SE(3)-Transformer / Equiformer**:球谐特征 + 等变注意力,用于分子性质预测和蛋白质结构
54
+ - **Set Transformer**:$S_n$ 置换等变注意力 + Induced Set Attention(低秩诱导点降复杂度)
55
+ - **G-CNN 注意力**:$D_n$ 旋转/镜像等变,用于遥感图像和医学影像
56
+
57
+ ## GPU 可行性
58
+ - **维度 1 张量化 ✅**:群作用实现为 $\rho(g)$ 矩阵乘,等变特征为 batched 张量
59
+ - **维度 2 GEMM 可映射 ✅**:$\rho(g) X$ 和 $Q K^T$ 均为 GEMM;$|G|$ 个群元素 → batched GEMM
60
+ - **维度 3 复杂度 ⚠️**:$|G|$ 倍计算量,小群($|D_4|=8$)可接受,大群($|S_n|=n!$)不可。改造:用生成元 + Cayley 图传播替代整群枚举
61
+ - **维度 4 显存 ⚠️**:需存储 $|G|$ 份中间特征,可分块 + gradient checkpointing
62
+ - **维度 5 低精度 ✅**:正交表示矩阵在 bf16 下数值稳定
63
+ - **维度 6 并行 ✅**:$|G|$ 个群元素天然并行(batch 维)
64
+ - **维度 7 稀疏 ⚠️**:置换 $\rho(g)$ 极度稀疏,可编码为 gather 索引
65
+ - **维度 8 算子融合 ✅**:群作用 + 线性变换可融合为单次 batched GEMM
66
+
67
+ ## 论文表述方式
68
+ "我们提出等变注意力机制,通过将注意力权重约束为群不变量、注意力输出约束为群等变量,在不增加数据增强的情况下将对称群 $G$ 的归纳偏置直接编码进模型结构,参数效率提升 $|G|/|stab|$ 倍。"
69
+
70
+ ## 风险
71
+ - **群选择错误的代价**:若数据不具有假定的对称性(如分子不具有完全 $E(3)$ 对称性),等变约束会伤害表达能力。需先验证对称性假设,或使用"近似等变"(soft equivariance)。
72
+ - **高阶表示的显存爆炸**:$SO(3)$ 的 $L$ 阶球谐表示维度为 $(2L+1)^2$,高阶特征 ($L \geq 3$) 的存储和计算量急剧增长。实践中通常截断到 $L \leq 2$。
@@ -0,0 +1,73 @@
1
+ # Geometry-Aware Attention
2
+ > **Rigor disclaimer**: Claims about complexity, memory, FlashAttention fusion, Tensor Core, and KV-Cache compression are marked as ✅ verified / ⚠️ retrofittable (needs validation) / ❌ infeasible. Unmarked claims are theoretically possible but require engineering validation.
3
+
4
+ ## Applicable Problems
5
+ When **known geometric relationships** exist between tokens/keys (spatial distance, manifold geodesic distance, hierarchical structure, temporal interval), the position-agnostic inner product of standard attention cannot exploit this structural information. Geometry-aware attention **directly injects geometric priors into attention weight computation**, enabling the model to naturally respect the metric structure of the underlying space. Typical scenarios include: 3D scene understanding, molecular conformation, temporal forecasting, hierarchical text structure (paragraph-sentence-word), and knowledge graphs.
6
+
7
+ ## Mathematical Inspiration
8
+ - Lenses: [symmetry (metric invariance), duality (coordinate-system-independent representation)]
9
+ - Knowledge: [`../../knowledge-base/information-geometry/fisher-metric.md` (geometric metrics on distribution spaces), `../../knowledge-base/probability/concentration-inequality.md` (concentration behavior under geometric constraints)]
10
+
11
+ ## Required Mathematical Knowledge
12
+ - **Metric Spaces and Distance Functions**: Euclidean distance, geodesic distance, tree distance, Wasserstein distance
13
+ - **RBF / Kernel Methods**: $k(x, y) = \exp(-d(x,y)^2 / 2\sigma^2)$, converting distance to similarity
14
+ - **Geometric Interpretation of Positional Encoding**: RoPE = action of the rotation group $SO(2)$ (relative distance encoded as rotation angle difference); ALiBi = exponentially decaying distance bias
15
+
16
+ ## AI Module Form
17
+
18
+ **Core Idea**: Explicitly introduce a geometric distance term into attention scores so that attention to distant tokens naturally decays:
19
+
20
+ $$\text{GeoAttn}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d}} + \text{GeoBias}(i, j)\right) V$$
21
+
22
+ **Scheme A: Distance-Biased Attention (General Metric Spaces)**:
23
+ ```python
24
+ # d_ij is the geometric distance between token i and j (precomputed or computed online)
25
+ # Learnable distance bias function
26
+ distance_bias = MLP(d_ij) # or simply -alpha * d_ij
27
+ scores = (Q @ K.T) / sqrt(d) + distance_bias
28
+ attn = softmax(scores) @ V
29
+ ```
30
+
31
+ **Scheme B: Relative Positional Encoding (Geometric Generalization of RoPE / ALiBi)**:
32
+ ```python
33
+ # Generalize RoPE: position -> group element g_i, relative position -> g_i g_j^{-1}
34
+ # Learnable relative position bias on arbitrary metric spaces
35
+ def geo_attention(Q, K, V, positions):
36
+ rel_pos = pairwise_difference(positions) # (n, n, coord_dim)
37
+ geo_bias = geo_encoder(rel_pos) # (n, n) learnable mapping
38
+ scores = (Q @ K.T) / sqrt(d) + geo_bias
39
+ return softmax(scores) @ V
40
+ ```
41
+
42
+ **Scheme C: Manifold-Aware Attention (Non-Euclidean Spaces)**:
43
+ ```python
44
+ # When tokens reside on a non-Euclidean manifold (hyperbolic space, sphere),
45
+ # use geodesic distance instead of Euclidean distance
46
+ def manifold_attention(Q, K, V, manifold):
47
+ geodist = manifold.geodesic_distance_matrix(positions) # (n, n)
48
+ geo_kernel = exp(-geodist^2 / (2 * sigma^2)) # RBF kernel
49
+ scores = (Q @ K.T) / sqrt(d) + log(geo_kernel + eps)
50
+ return softmax(scores) @ V
51
+ ```
52
+
53
+ ## Implementable Architectures
54
+ - **RoPE Extensions**: From $SO(2)$ rotations to higher-dimensional rotation groups $SO(2k)$, encoding multi-dimensional positional information (2D image patches, 3D voxels)
55
+ - **Hierarchical Positional Bias**: Use LCA (Lowest Common Ancestor) depth as distance in tree structures, suitable for hierarchical geometric of documents and code
56
+ - **Molecular Conformation Attention**: 3D atomic coordinates -> distance matrix -> geometric bias, used in molecular GNNs and protein structure prediction
57
+
58
+ ## GPU Feasibility
59
+ - **Dimension 1 Tensorization**: Distance matrices and bias matrices are dense tensors with element-wise operations
60
+ - **Dimension 2 GEMM-mappability**: The main body $Q K^T$ is standard GEMM; geometric bias is additive and does not interrupt GEMM
61
+ - **Dimension 3 Complexity**: Pairwise distance matrix construction and storage are $O(n^2)$; however, block-wise computation + online softmax can avoid materializing the full matrix
62
+ - **Dimension 4 Memory**: The $n \times n$ distance matrix occupies GPU memory; mitigated by block/streaming computation (compatible with FlashAttention)
63
+ - **Dimension 5 Low Precision**: Distance computation and bias addition are stable under bf16; the exp in RBF requires overflow caution (clamp distances)
64
+ - **Dimension 6 Parallelism**: Distance computation and attention can be pipelined; pairwise distances can be computed in parallel blocks
65
+ - **Dimension 7 Sparsity**: Distant biases tend toward $-\infty$ (approaching zero after softmax), naturally inducing structured sparsity (local attention windows)
66
+ - **Dimension 8 Operator Fusion**: Geometric bias can be fused into FlashAttention's online softmax loop (added after $QK^T$, before softmax)
67
+
68
+ ## Paper Phrasing
69
+ "We propose geometry-aware attention, which explicitly injects learnable geometric distance bias terms into attention scores, enabling the model to naturally respect the metric structure of the input space. This achieves exponential decay of attention to distant tokens without increasing parameter count, while maintaining compatibility with FlashAttention."
70
+
71
+ ## Risks
72
+ - **Geometric Prior Conflicting with Data**: If geometric distance is inconsistent with semantic relevance (e.g., distant but semantically related tokens in text), strong geometric bias will impair model expressiveness. The bias should be learnable and overridable by content-based attention.
73
+ - **Non-Differentiability of Distance Computation**: Certain distances (graph shortest path, tree LCA depth) are non-differentiable or computationally expensive. Differentiable relaxations (softmin instead of min) or precomputed distance matrices are needed.
@@ -0,0 +1,72 @@
1
+ # 几何感知注意力 / Geometry-Aware Attention
2
+ > **严谨性声明**:本文件中涉及复杂度、显存、FlashAttention 融合、Tensor Core、KV-Cache 压缩的结论均标注为「✅ 已验证 / ⚠️ 可改造需验证 / ❌ 不可行」。未标注的视为理论可行,需工程验证。
3
+
4
+ ## 适用问题
5
+ 当 token/key 之间存在**已知的几何关系**(空间距离、流形测地距、层级结构、时序间隔)时,标准注意力的位置无关内积无法利用这些结构信息。几何感知注意力将**几何先验直接注入注意力权重计算**,使模型天然尊重底空间的度量结构。典型场景:3D 场景理解、分子构象、时序预测、层级文本结构(段落-句子-词)、知识图谱。
6
+
7
+ ## 数学思想来源
8
+ - 透镜:[symmetry(对称透镜 — 度量不变性), duality(对偶透镜 — 坐标系无关表达)]
9
+ - 知识:[`../../knowledge-base/information-geometry/fisher-metric.md`(分布空间的几何度量), `../../knowledge-base/probability/concentration-inequality.md`(几何约束下的浓度行为)]
10
+
11
+ ## 需要的数学知识
12
+ - **度量空间与距离函数**:欧氏距离、测地距、树距离、Wasserstein 距离
13
+ - **RBF / 核方法**:$k(x, y) = \exp(-d(x,y)^2 / 2\sigma^2)$,距离→相似度的转换
14
+ - **位置编码的几何解释**:RoPE = 旋转群 $SO(2)$ 的作用(相对距离编码为旋转角度差);ALiBi = 指数衰减的距离偏置
15
+
16
+ ## AI 模块形式
17
+
18
+ **核心思路**:在注意力分数中显式引入几何距离项,使远距离 token 的注意力天然衰减:
19
+
20
+ $$\text{GeoAttn}(Q, K, V) = \text{softmax}\left(\frac{QK^T}{\sqrt{d}} + \text{GeoBias}(i, j)\right) V$$
21
+
22
+ **方案 A:距离偏置注意力(通用度量空间)**:
23
+ ```python
24
+ # d_ij 为 token i 和 j 之间的几何距离(预计算或在线计算)
25
+ # 可学习距离偏置函数
26
+ distance_bias = MLP(d_ij) # 或简单的 -α * d_ij
27
+ scores = (Q @ K.T) / sqrt(d) + distance_bias
28
+ attn = softmax(scores) @ V
29
+ ```
30
+
31
+ **方案 B:相对位置编码(RoPE / ALiBi 的几何推广)**:
32
+ ```python
33
+ # 推广 RoPE:位置 → 群元素 g_i,相对位置 → g_i g_j^{-1}
34
+ # 可学习任意度量空间上的相对位置偏置
35
+ def geo_attention(Q, K, V, positions):
36
+ rel_pos = pairwise_difference(positions) # (n, n, coord_dim)
37
+ geo_bias = geo_encoder(rel_pos) # (n, n) 可学习映射
38
+ scores = (Q @ K.T) / sqrt(d) + geo_bias
39
+ return softmax(scores) @ V
40
+ ```
41
+
42
+ **方案 C:流形感知注意力(非欧空间)**:
43
+ ```python
44
+ # token 位于非欧流形(双曲空间、球面)时,用测地距替代欧氏距
45
+ def manifold_attention(Q, K, V, manifold):
46
+ geodist = manifold.geodesic_distance_matrix(positions) # (n, n)
47
+ geo_kernel = exp(-geodist^2 / (2 * sigma^2)) # RBF 核
48
+ scores = (Q @ K.T) / sqrt(d) + log(geo_kernel + eps)
49
+ return softmax(scores) @ V
50
+ ```
51
+
52
+ ## 可实现结构
53
+ - **RoPE 扩展**:从 $SO(2)$ 旋转到更高维旋转群 $SO(2k)$,编码多维位置信息(2D 图像 patch、3D voxel)
54
+ - **层级位置偏置**:树结构中用 LCA(最近公共祖先)深度作为距离,适合文档/代码的层级建模
55
+ - **分子构象注意力**:3D 原子坐标 → 距离矩阵 → 几何偏置,用于分子 GNN 和蛋白质结构预测
56
+
57
+ ## GPU 可行性
58
+ - **维度 1 张量化 ✅**:距离矩阵和偏置矩阵均为稠密张量,逐元素运算
59
+ - **维度 2 GEMM 可映射 ✅**:主体 $Q K^T$ 为标准 GEMM;几何偏置为加法,不阻断 GEMM
60
+ - **维度 3 复杂度 ⚠️**:成对距离矩阵 $O(n^2)$ 构建和存储;但可用分块计算 + online softmax 避免物化完整矩阵
61
+ - **维度 4 显存 ⚠️**:$n \times n$ 距离矩阵占用显存;可分块/流式计算(与 FlashAttention 兼容)
62
+ - **维度 5 低精度 ✅**:距离计算和偏置加法在 bf16 下稳定;RBF 的 exp 需注意上溢(clamp 距离)
63
+ - **维度 6 并行 ✅**:距离计算和注意力可流水线并行,成对距离可分块并行
64
+ - **维度 7 稀疏 ✅**:远距离偏置趋于 $-\infty$(softmax 后趋零),天然诱导结构化稀疏(局部注意力窗口)
65
+ - **维度 8 算子融合 ✅**:几何偏置可融入 FlashAttention 的 online softmax 循环中(加在 $QK^T$ 之后、softmax 之前)
66
+
67
+ ## 论文表述方式
68
+ "我们提出几何感知注意力,通过在注意力分数中显式注入可学习的几何距离偏置项,使模型天然尊重输入空间的度量结构,在不增加参数量的情况下将远距离 token 的注意力指数衰减,同时保持与 FlashAttention 的兼容性。"
69
+
70
+ ## 风险
71
+ - **几何先验与数据冲突**:若几何距离与语义相关性不一致(如文本中远距离但语义相关的 token),强几何偏置会伤害模型表达。需让偏置可学习且可被内容注意力覆盖。
72
+ - **距离计算的非可微性**:某些距离(图最短路径、树 LCA 深度)不可微或计算复杂。需使用可微松弛(softmin 替代 min)或预计算距离矩阵。