math-skill 3.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/README.en-US.md +50 -30
  2. package/README.md +26 -6
  3. package/agents/math-critic.en.md +30 -28
  4. package/agents/math-critic.md +30 -30
  5. package/commands/ask.en.md +15 -0
  6. package/commands/ask.md +6 -1
  7. package/design-patterns/attention/equivariant-attention.en.md +17 -11
  8. package/design-patterns/attention/equivariant-attention.md +16 -10
  9. package/design-patterns/attention/geometry-aware-attention.en.md +11 -11
  10. package/design-patterns/attention/geometry-aware-attention.md +10 -10
  11. package/design-patterns/attention/information-bottleneck-attention.en.md +40 -20
  12. package/design-patterns/attention/information-bottleneck-attention.md +40 -20
  13. package/design-patterns/attention/projection-attention.en.md +12 -12
  14. package/design-patterns/attention/projection-attention.md +11 -11
  15. package/design-patterns/attention/spectral-attention.en.md +27 -13
  16. package/design-patterns/attention/spectral-attention.md +26 -12
  17. package/design-patterns/compression/leverage-score-selection.en.md +14 -14
  18. package/design-patterns/compression/leverage-score-selection.md +14 -14
  19. package/design-patterns/compression/low-rank-kv-cache.en.md +40 -13
  20. package/design-patterns/compression/low-rank-kv-cache.md +39 -13
  21. package/design-patterns/compression/spectral-token-pruning.en.md +17 -15
  22. package/design-patterns/compression/spectral-token-pruning.md +17 -15
  23. package/design-patterns/compression/topology-preserving-compression.en.md +11 -11
  24. package/design-patterns/compression/topology-preserving-compression.md +11 -11
  25. package/design-patterns/loss/constraint-penalty.en.md +9 -5
  26. package/design-patterns/loss/constraint-penalty.md +10 -7
  27. package/design-patterns/loss/contrastive-loss.en.md +38 -12
  28. package/design-patterns/loss/contrastive-loss.md +39 -13
  29. package/design-patterns/loss/information-bottleneck-loss.en.md +6 -6
  30. package/design-patterns/loss/information-bottleneck-loss.md +7 -7
  31. package/design-patterns/loss/orthogonality-loss.en.md +25 -18
  32. package/design-patterns/loss/orthogonality-loss.md +25 -19
  33. package/design-patterns/loss/variational-loss.en.md +5 -5
  34. package/design-patterns/loss/variational-loss.md +6 -6
  35. package/design-patterns/overview.en.md +36 -0
  36. package/design-patterns/overview.md +36 -0
  37. package/design-patterns/representation/equivariant-split.en.md +5 -5
  38. package/design-patterns/representation/equivariant-split.md +5 -6
  39. package/design-patterns/representation/manifold-representation.en.md +13 -13
  40. package/design-patterns/representation/manifold-representation.md +14 -15
  41. package/design-patterns/representation/shared-private-decomposition.en.md +13 -8
  42. package/design-patterns/representation/shared-private-decomposition.md +13 -10
  43. package/design-patterns/representation/subspace-alignment.en.md +13 -13
  44. package/design-patterns/representation/subspace-alignment.md +13 -13
  45. package/design-patterns/routing/graph-routing.en.md +12 -12
  46. package/design-patterns/routing/graph-routing.md +12 -12
  47. package/design-patterns/routing/moe-routing.en.md +13 -13
  48. package/design-patterns/routing/moe-routing.md +13 -15
  49. package/design-patterns/routing/optimal-transport-routing.en.md +6 -6
  50. package/design-patterns/routing/optimal-transport-routing.md +7 -7
  51. package/design-patterns/routing/spectral-clustering-routing.en.md +27 -16
  52. package/design-patterns/routing/spectral-clustering-routing.md +27 -18
  53. package/knowledge-base/differential-geometry/connection.en.md +17 -2
  54. package/knowledge-base/differential-geometry/connection.md +17 -2
  55. package/knowledge-base/differential-geometry/curvature.en.md +14 -1
  56. package/knowledge-base/differential-geometry/curvature.md +14 -1
  57. package/knowledge-base/differential-geometry/geodesic.en.md +16 -2
  58. package/knowledge-base/differential-geometry/geodesic.md +16 -2
  59. package/knowledge-base/differential-geometry/index.en.md +52 -0
  60. package/knowledge-base/differential-geometry/index.md +52 -0
  61. package/knowledge-base/differential-geometry/manifold.en.md +15 -2
  62. package/knowledge-base/differential-geometry/manifold.md +15 -2
  63. package/knowledge-base/differential-geometry/metric-tensor.en.md +16 -2
  64. package/knowledge-base/differential-geometry/metric-tensor.md +17 -3
  65. package/knowledge-base/differential-geometry/tangent-space.en.md +17 -3
  66. package/knowledge-base/differential-geometry/tangent-space.md +17 -3
  67. package/knowledge-base/information-geometry/fisher-metric.en.md +32 -13
  68. package/knowledge-base/information-geometry/fisher-metric.md +32 -13
  69. package/knowledge-base/information-geometry/index.en.md +45 -0
  70. package/knowledge-base/information-geometry/index.md +45 -0
  71. package/knowledge-base/information-geometry/natural-gradient.en.md +24 -10
  72. package/knowledge-base/information-geometry/natural-gradient.md +24 -10
  73. package/knowledge-base/lie-theory/equivariance.en.md +18 -3
  74. package/knowledge-base/lie-theory/equivariance.md +18 -3
  75. package/knowledge-base/lie-theory/group-action.en.md +16 -2
  76. package/knowledge-base/lie-theory/group-action.md +16 -2
  77. package/knowledge-base/lie-theory/index.en.md +52 -0
  78. package/knowledge-base/lie-theory/index.md +52 -0
  79. package/knowledge-base/lie-theory/lie-algebra.en.md +17 -2
  80. package/knowledge-base/lie-theory/lie-algebra.md +17 -2
  81. package/knowledge-base/lie-theory/lie-group.en.md +17 -3
  82. package/knowledge-base/lie-theory/lie-group.md +17 -3
  83. package/knowledge-base/lie-theory/representation.en.md +17 -2
  84. package/knowledge-base/lie-theory/representation.md +17 -2
  85. package/knowledge-base/matrix-analysis/index.en.md +49 -0
  86. package/knowledge-base/matrix-analysis/index.md +49 -0
  87. package/knowledge-base/matrix-analysis/low-rank-approximation.en.md +20 -7
  88. package/knowledge-base/matrix-analysis/low-rank-approximation.md +20 -7
  89. package/knowledge-base/matrix-analysis/matrix-perturbation.en.md +13 -1
  90. package/knowledge-base/matrix-analysis/matrix-perturbation.md +13 -1
  91. package/knowledge-base/matrix-analysis/positive-semidefinite.en.md +20 -6
  92. package/knowledge-base/matrix-analysis/positive-semidefinite.md +20 -6
  93. package/knowledge-base/matrix-analysis/projection.en.md +14 -1
  94. package/knowledge-base/matrix-analysis/projection.md +14 -1
  95. package/knowledge-base/matrix-analysis/spectral-decomposition.en.md +14 -1
  96. package/knowledge-base/matrix-analysis/spectral-decomposition.md +14 -1
  97. package/knowledge-base/optimization/constrained-optimization.en.md +17 -3
  98. package/knowledge-base/optimization/constrained-optimization.md +17 -3
  99. package/knowledge-base/optimization/convex-optimization.en.md +15 -2
  100. package/knowledge-base/optimization/convex-optimization.md +15 -2
  101. package/knowledge-base/optimization/index.en.md +50 -0
  102. package/knowledge-base/optimization/index.md +50 -0
  103. package/knowledge-base/optimization/lagrangian-duality.en.md +18 -4
  104. package/knowledge-base/optimization/lagrangian-duality.md +18 -4
  105. package/knowledge-base/optimization/proximal-method.en.md +15 -1
  106. package/knowledge-base/optimization/proximal-method.md +15 -1
  107. package/knowledge-base/optimization/riemannian-optimization.en.md +18 -4
  108. package/knowledge-base/optimization/riemannian-optimization.md +18 -4
  109. package/knowledge-base/overview.en.md +20 -8
  110. package/knowledge-base/overview.md +20 -8
  111. package/knowledge-base/probability/concentration-inequality.en.md +21 -7
  112. package/knowledge-base/probability/concentration-inequality.md +21 -7
  113. package/knowledge-base/probability/entropy.en.md +24 -8
  114. package/knowledge-base/probability/entropy.md +23 -7
  115. package/knowledge-base/probability/fisher-information.en.md +24 -10
  116. package/knowledge-base/probability/fisher-information.md +24 -10
  117. package/knowledge-base/probability/index.en.md +51 -0
  118. package/knowledge-base/probability/index.md +51 -0
  119. package/knowledge-base/probability/information-bottleneck.en.md +24 -8
  120. package/knowledge-base/probability/information-bottleneck.md +24 -8
  121. package/knowledge-base/probability/kl-divergence.en.md +21 -8
  122. package/knowledge-base/probability/kl-divergence.md +21 -8
  123. package/knowledge-base/topology/euler-characteristic.en.md +15 -2
  124. package/knowledge-base/topology/euler-characteristic.md +15 -2
  125. package/knowledge-base/topology/fundamental-group.en.md +16 -2
  126. package/knowledge-base/topology/fundamental-group.md +16 -2
  127. package/knowledge-base/topology/index.en.md +48 -0
  128. package/knowledge-base/topology/index.md +48 -0
  129. package/knowledge-base/topology/persistent-homology.en.md +17 -2
  130. package/knowledge-base/topology/persistent-homology.md +17 -2
  131. package/lenses/algorithmic.en.md +1 -1
  132. package/lenses/algorithmic.md +1 -1
  133. package/lenses/axiomatization.en.md +1 -1
  134. package/lenses/axiomatization.md +1 -1
  135. package/lenses/categorical.en.md +1 -1
  136. package/lenses/categorical.md +1 -1
  137. package/lenses/causal.en.md +1 -1
  138. package/lenses/causal.md +1 -1
  139. package/lenses/duality.en.md +1 -1
  140. package/lenses/duality.md +1 -1
  141. package/lenses/game.en.md +2 -2
  142. package/lenses/game.md +2 -2
  143. package/lenses/geometric.en.md +1 -1
  144. package/lenses/geometric.md +1 -1
  145. package/lenses/local-to-global.en.md +1 -1
  146. package/lenses/local-to-global.md +1 -1
  147. package/lenses/perturbation.en.md +1 -1
  148. package/lenses/perturbation.md +1 -1
  149. package/lenses/probabilistic.en.md +1 -1
  150. package/lenses/probabilistic.md +1 -1
  151. package/lenses/projection.en.md +1 -1
  152. package/lenses/projection.md +1 -1
  153. package/lenses/spectral.en.md +2 -2
  154. package/lenses/spectral.md +2 -2
  155. package/lenses/symmetry.en.md +1 -1
  156. package/lenses/symmetry.md +1 -1
  157. package/lenses/topological.en.md +2 -2
  158. package/lenses/topological.md +2 -2
  159. package/lenses/variational.en.md +1 -1
  160. package/lenses/variational.md +1 -1
  161. package/package.json +5 -5
  162. package/references/agentic-workflow.en.md +3 -3
  163. package/references/agentic-workflow.md +1 -1
  164. package/references/books/abstract-algebra.en.md +124 -0
  165. package/references/books/abstract-algebra.md +17 -17
  166. package/references/books/algebraic-geometry-rising-sea.en.md +171 -0
  167. package/references/books/algebraic-geometry-rising-sea.md +7 -7
  168. package/references/books/differential-geometry.en.md +140 -0
  169. package/references/books/differential-geometry.md +23 -23
  170. package/references/books/matrix-analysis.en.md +146 -0
  171. package/references/books/matrix-analysis.md +32 -32
  172. package/references/books/micro-lie-theory.en.md +116 -0
  173. package/references/books/micro-lie-theory.md +16 -16
  174. package/references/books/optimization-ml.en.md +163 -0
  175. package/references/books/optimization-ml.md +20 -21
  176. package/references/books/smooth-manifolds.en.md +105 -0
  177. package/references/books/smooth-manifolds.md +15 -15
  178. package/references/gpu-friendly-math.en.md +35 -9
  179. package/references/gpu-friendly-math.md +33 -5
  180. package/references/skill-index.en.md +105 -0
  181. package/references/skill-index.md +105 -0
  182. package/skills/math-research-activator/SKILL.en.md +72 -88
  183. package/skills/math-research-activator/SKILL.md +61 -78
@@ -0,0 +1,140 @@
1
+ # Manifolds & Differential Geometry
2
+
3
+ > **Manifolds and Differential Geometry** -- Jeffrey M. Lee
4
+ > American Mathematical Society, *Graduate Studies in Mathematics*, Volume 107 (2009), ISBN 978-0-8218-4815-9.
5
+ > MSC: 58A05, 53C05, 22E15, 53C20, 53B30, 55R10. This file is an "activation" summary, not a verbatim transcription; for full-fidelity lookups see the "Deep-dive Entry" at the end.
6
+
7
+ ## Overview
8
+
9
+ This book is a graduate-level textbook that builds from scratch: **smooth manifold -> tensors / differential forms -> connections and curvature -> Riemannian geometry**. Its central thread is not "computing in Euclidean space" but rather **doing calculus on curved spaces**: when there are no global coordinates and no "natural" vector addition, how does one define differentiation, compare vectors at different points, and measure distance and curvature? This is precisely the language deep learning needs once the default assumption that "parameter space is flat Euclidean" is abandoned.
10
+
11
+ A remark in the preface is critically important for AI research: **a connection on a fiber bundle and a gauge field in physics are the same concept, independently discovered by mathematicians and physicists** (preface, footnote 2). This is the archetype of the "cross-domain activation" that this skill pack repeatedly emphasizes -- the structure was already there; what was missing was someone connecting it to algorithm design (gauge-equivariant networks are the product of exactly that connection).
12
+
13
+ Actual chapter map (ordered by dependency; chapter and section numbers verified against the PDF table of contents):
14
+
15
+ | Ch | Title | Hook to AI |
16
+ |----|-------|-----------|
17
+ | 1-2 | Differentiable Manifolds / The Tangent Structure | Tangent space = local linearization, the space to which gradients belong |
18
+ | 3 | Immersion and Submersion | Submanifolds, dimensionality reduction / embedding |
19
+ | 4 | Curves and Hypersurfaces in Euclidean Space | Geometric intuition source for Gauss / mean curvature |
20
+ | 5 | Lie Groups | Continuous symmetry groups, exponential map, adjoint representation -> equivariant architectures |
21
+ | 6 | Fiber Bundles (S6.1 general bundles, S6.2 vector bundles, S6.8 principal and associated bundles) | **Geometric skeleton of gauge equivariance** |
22
+ | 7 | Tensors (S7.6 Metric Tensors) | Metric tensor g = inner-product field -> Fisher metric |
23
+ | 8 | Differential Forms (S8.5 bundle-valued forms) | Antisymmetric tensors, exterior derivative, gauge field strength |
24
+ | 9 | Integration and Stokes' Theorem (S9.8 Electromagnetism) | Maxwell = instantiation of U(1) connection curvature |
25
+ | 10 | De Rham Cohomology | Global topological invariants (integral conservation laws) |
26
+ | 11 | Distributions and Frobenius' Theorem | Integrability, constraint distributions |
27
+ | 12 | Connections and Covariant Derivatives (S12.2 connection forms, S12.4 Ehresmann, S12.5/S12.10 curvature, S12.12 G-connections) | **Parallel transport + curvature** |
28
+ | 13 | Riemannian & Semi-Riemannian Geometry (S13.1 Levi-Civita, S13.2 Riemann curvature, S13.4 geodesics, S13.7 Jacobi fields, S13.11 Rauch comparison) | **Natural gradient / optimization terrain** |
29
+
30
+ ## Core Structures Transferable to AI/Infra
31
+
32
+ Each entry follows **geometric concept -> mathematical core -> AI transfer**, making it easy to plug directly into algorithm design.
33
+
34
+ - **Riemannian metric g (S7.6 / S13.1) -> Natural gradient and information geometry.**
35
+ - Core: The metric tensor assigns an inner product <u,v>_g = u^T g v to the tangent space at each point, determining "what is close to what" and which direction counts as "steepest."
36
+ - Transfer: The natural metric on a family of probability distributions is the **Fisher information matrix (Fisher-Rao metric)**; parameter space is therefore not flat Euclidean but a curved manifold. The steepest-descent direction is not nabla L but **g^{-1} nabla L (natural gradient)**, which is invariant under reparameterization.
37
+ - **Connection / covariant derivative (S12.1-S12.4) -> Parallel transport.**
38
+ - Core: Tangent spaces at different points cannot be directly added; a connection nabla specifies "how to carry a vector along a curve to another point without introducing extra rotation." The **Levi-Civita connection** is the unique one that is metric-compatible and torsion-free.
39
+ - Transfer: Correctly transporting **momentum / historical gradients / second-order state** on the parameter manifold is the origin of vector transport in Riemannian SGD/Adam.
40
+ - **Curvature (S12.5 / S13.2 / S13.7) -> Optimization terrain (loss landscape).**
41
+ - Core: Curvature = how much a vector rotates after parallel transport around a small loop; it measures "whether the space is curved and whether paths are path-dependent," and is essentially the geometric avatar of the Hessian.
42
+ - Transfer: The curvature of the loss surface determines the condition number and sharpness; **Jacobi fields / Rauch comparison theorem (S13.7 / S13.11)** describe geodesic divergence-convergence, equivalent to stability vs. divergence of optimization trajectories.
43
+ - **Geodesics and exponential map (S13.4) -> "Straight-line steps" on a manifold.**
44
+ - Core: Geodesics are locally shortest paths; the exponential map exp_p(v) maps a tangent vector v back to the endpoint of the corresponding shortest path on the manifold.
45
+ - Transfer: When doing **constrained optimization** on SPD matrices, Stiefel / Grassmann manifolds, exp_p is the exact version of a retraction; geodesic interpolation in latent space respects the data manifold better than Euclidean straight lines.
46
+ - **Fiber bundles / principal bundles + G-connections (S6.8 / S12.12 / S9.8) -> Gauge equivariance.**
47
+ - Core: A principal G-bundle packages "the arbitrary choice of local coordinate system / frame" as a group action on fibers; a connection on the bundle = gauge field, curvature = field strength.
48
+ - Transfer: Physical quantities should not depend on the choice of local frame; this "gauge freedom" is precisely the inductive bias behind **gauge-equivariant CNNs (convolution on spheres / meshes / general manifolds)**; S9.8 uses Maxwell's equations to provide a concrete example of U(1) connection curvature.
49
+ - **Lie groups and Lie algebras (S5) -> Continuous symmetry as prior.**
50
+ - Core: The exponential map exp: g -> G and the adjoint representation Ad provide the passage "infinitesimal generator -> finite transformation."
51
+ - Transfer: Encoding the symmetry group as a hard inductive bias of the network (equivariant layers, Lie-algebra-parameterized rotations / rigid-body transformations).
52
+
53
+ ## Problem Types Suited for Activation
54
+
55
+ - Optimization is **ill-conditioned / converges slowly under Euclidean assumptions**, but the underlying parameters have a natural probabilistic or geometric structure (use a metric to redefine "distance").
56
+ - Data itself lives on **non-Euclidean manifolds**: covariance / SPD matrices, rotations SO(3), directional data, graphs and meshes, spherical signals.
57
+ - Need **rigorous symmetry / equivariance guarantees**: outputs transform predictably under rotations, translations, and local gauge transformations.
58
+ - Need to explicitly model **"arbitrariness of coordinate choice"** as a symmetry (multi-view, multi-frame, sensor-pose invariance).
59
+ - Want to use **geometric quantities (curvature / geodesic distance) for regularization or diagnostics**: sharpness, generalization, trajectory stability.
60
+
61
+ ## Possible Algorithmic Inspirations
62
+
63
+ - **Natural gradient / K-FAC**: Use the Fisher metric as preconditioner; update direction = F^{-1} nabla L rather than nabla L.
64
+ - Key engineering: K-FAC approximates the per-layer Fisher as a Kronecker product **F ~ A (x) B** (A from input activations, B from output gradients); inversion reduces to inverting two small matrices, and the preconditioner application becomes a small GEMM (see scorecard below).
65
+ - **Information-geometric optimization**: View training as moving along Fisher-Rao geodesics on the distribution manifold.
66
+ - Mirror descent, Bregman divergences, and dual coordinates of exponential families are all special cases of this Hessian-metric framework; can be used to design optimizers insensitive to parameterization.
67
+ - **Riemannian optimization**: SGD/Adam on SPD / Stiefel / Grassmann / hyperbolic manifolds.
68
+ - The toolkit of three: retraction (a cheap approximation of exp), vector transport (a discrete version of parallel transport), momentum on manifolds; commonly used in metric learning, orthogonality constraints, hierarchical structure embeddings.
69
+ - **Gauge-equivariant CNN**: Introduce local gauge frames when convolving on manifolds / meshes.
70
+ - Use G-connections to align frames at neighboring points so that features are invariant to local coordinate choices; applicable to spherical signals, meshes, lattices, and other domains without global coordinates.
71
+ - **Curvature regularization / geometric perspective on SAM**: Use Hessian-vector products to estimate curvature.
72
+ - Penalize sharp minima (flat-minima preference), or use Jacobi fields to characterize trajectory divergence, providing a geometric interpretation for sharpness-aware training.
73
+ - **Geodesic interpolation and manifold augmentation**: Interpolate and sample along geodesics in latent / embedding space; respects the data manifold better than Euclidean straight lines; applicable to data augmentation and controllable generation.
74
+
75
+ ## GPU Friendliness Warning
76
+
77
+ > Evaluate item by item using the **eight-dimension scorecard** from `../gpu-friendly-math.en.md`. The biggest pitfall in differential geometry is "inversion and materialization of metric / curvature matrices."
78
+
79
+ - **D2/D3**: Inversion is the make-or-break line. Naive natural gradient requires inverting the N x N Fisher, where N is the parameter count (~10^9); O(N^3) inversion + O(N^2) memory means **immediate disqualification**.
80
+ - **Adaptable [v]**: **K-FAC** blocks F into a Kronecker product A (x) B, exploiting (A (x) B)^{-1} = A^{-1} (x) B^{-1}; only two small factors need inversion, and applying the preconditioner to the gradient **is a GEMM**. This is the affirmative answer to "can Kronecker factorization reduce to GEMM" -- yes, and this is the only form that can scale to a cluster.
81
+ - **D4**: Do not materialize the full Hessian / full curvature tensor. The Riemann curvature tensor is order 4; full materialization blows up memory. Use **Hessian-vector products (HVP)** to extract curvature information in O(N) via a single backward pass, avoiding N x N.
82
+ - **D5**: Fisher / metric matrices are often ill-conditioned. Inversion under bf16/fp16 catastrophically amplifies errors; **must add damping (Tikhonov, F + lambda I)** and keep inversion in fp32; otherwise it violates "low-precision stability."
83
+ - **D6**: Parallel transport / geodesics are serial ODEs. Integrating the connection equation along a curve is a long serial recurrence with poor parallelism; in practice, one uses **single-step retractions / closed-form parallel transport** (analytic formulas exist for specific manifolds) instead of step-by-step integration.
84
+ - **D1/D2**: Group convolution can be friendly, but continuous groups require caution. Discrete groups (e.g., C_n, octahedral group) admit group convolutions that expand into GEMM [v]; continuous Lie groups require discretization by sampling, and improper sampling can break equivariance + produce irregular gather/scatter (D7 Sparsity unfriendly).
85
+
86
+ **Natural gradient / K-FAC eight-dimension scorecard (worked example):**
87
+
88
+ | D | Naive Natural Gradient (full Fisher inversion) | K-FAC (Kronecker factorization) |
89
+ |-----------|------------------------------------------------|--------------------------------|
90
+ | D1 | [x] explicit large-matrix inverse | [v] batched small-matrix algebra |
91
+ | D2 | [x] N x N inversion, not GEMM-able | [v] A^{-1} (x) B^{-1} application = GEMM chain |
92
+ | D3 | [x] O(N^3) | [v] two small factors, sub-cubic |
93
+ | D4 | [x] materialize N x N | [v] store only two small factors |
94
+ | D5 | [x] ill-conditioned, needs fp64 | [~] add damping + fp32 inversion, adaptable |
95
+ | D6 | [~] single large inversion hard to parallelize | [v] per-layer factors independent, parallelizable |
96
+ | D7 | -- | [v] block-diagonal structure |
97
+ | D8 | [x] | [v] preconditioner can be fused into optimizer kernel |
98
+
99
+ **Conclusion**: Riemannian / information-geometric methods **become GPU-feasible only when the metric is structurally factored (Kronecker / block-diagonal / low-rank)**; exact inversion and exact parallel transport are "beautiful but incomputable" and must be adapted or eliminated.
100
+
101
+ ## Which Thinking Lens to Invoke
102
+
103
+ - **symmetry (symmetry and invariance) -- primary.** Gauge equivariance, Lie group symmetry, fiber bundles = encoding "frame / coordinate-choice invariance" as symmetry; the strongest interface between this book and DL.
104
+ - **variational -- co-primary.** Natural gradient, Riemannian SGD, curvature regularization are all "finding optima in curved constrained spaces."
105
+ - **duality**: Exponential / logarithmic maps, retractions, coordinate transformations to simplify problems.
106
+ - **geometric**: Explicitly model parameter / data spaces as manifolds, then translate back to algorithms.
107
+ - **topological**: Auxiliary -- de Rham cohomology / global invariants for conservation laws and integrability diagnostics.
108
+
109
+ Recommended combination: First `symmetry` to establish the symmetry structure -> `variational` to arrive at natural gradient / Riemannian optimization -> `duality` to handle retractions -> pass through the `../gpu-friendly-math.en.md` acceptance gate.
110
+
111
+ ## Anti-patterns
112
+
113
+ Each entry gives **anti-pattern -> correct approach**:
114
+
115
+ - **Materializing and exactly inverting the full Fisher / full Hessian**: O(N^3) / O(N^2), infeasible on a cluster.
116
+ - Correct approach: First apply Kronecker / block-diagonal / low-rank factorization, then invert; without factorization, don't use natural gradient.
117
+ - **Directly inverting ill-conditioned metric matrices in fp16**: Catastrophic cancellation, results are noise.
118
+ - Correct approach: Add damping F + lambda I, keep inversion in fp32, use CG / Woodbury for implicit solves when necessary.
119
+ - **Step-by-step ODE integration for parallel transport / geodesics**: Serial recurrence kills parallelism.
120
+ - Correct approach: Use closed-form retractions / vector transport (analytic formulas exist for specific manifolds), replacing the recurrence with a single step.
121
+ - **Blindly discretizing continuous groups**: Equivariance silently breaks, and irregular gather/scatter patterns are introduced.
122
+ - Correct approach: Choose discrete subgroups that can be exactly represented, or use quadrature / frequency-domain (spherical harmonics) schemes with provable error bounds.
123
+ - **Forcing manifold structure for "geometric beauty"**: For the vast majority of tasks, Euclidean approximations suffice.
124
+ - Correct approach: Before introducing Riemannian machinery, first demonstrate experimentally that the Euclidean approach is genuinely ill-conditioned (condition number / convergence curves).
125
+ - **Treating curvature regularization as a panacea**: Curvature estimation is itself expensive and noisy.
126
+ - Correct approach: First validate the benefit at small scale using HVPs, confirm the signal-to-noise ratio, then scale up.
127
+
128
+ ## Deep-dive Entry
129
+
130
+ > **Bibliographic information**: Jeffrey M. Lee, *Manifolds and Differential Geometry*, Graduate Studies in Mathematics Vol. 107, American Mathematical Society, 2009. ISBN 978-0-8218-4815-9.
131
+ >
132
+ > **Activation method**: Place `Manifolds and Differential Geometry.pdf` in the `math_book/` folder at the project root; the Agent can then automatically search the original text. The PDF is not distributed via npm/git (copyright reasons) and must be obtained separately.
133
+
134
+ > Full-fidelity lookup = have the Agent **automatically search the local PDF** `math_book/Manifolds and Differential Geometry.pdf` (locate by chapter / section number; do not paraphrase from memory). This summary provides only coordinates, not a substitute for the original text.
135
+
136
+ - **S6.8 Principal and Associated Bundles** + **S12.12 G-Connections**: Geometric foundations of gauge equivariance (principal bundle + connection = gauge field).
137
+ - **S7.6 Metric Tensors** + **S13.1 Levi-Civita Connection**: The origin of metric tensors and natural gradient / Fisher metric.
138
+ - **S13.2 Riemann Curvature Tensor** + **S13.7 Jacobi Fields**: Curvature, optimization terrain, and trajectory stability.
139
+ - **S13.4 Geodesics** + **S13.11 Rauch's Comparison Theorem**: Geodesics / retractions and convergence-divergence comparison.
140
+ - **S9.8 Electromagnetism**: Gauge field as a concrete instance of U(1) connection curvature (a historical example of cross-domain activation).
@@ -1,4 +1,4 @@
1
- # 📐 流形与微分几何 / Manifolds & Differential Geometry
1
+ # 流形与微分几何 / Manifolds & Differential Geometry
2
2
 
3
3
  > **Manifolds and Differential Geometry** — Jeffrey M. Lee
4
4
  > American Mathematical Society, *Graduate Studies in Mathematics*, Volume 107 (2009), ISBN 978-0-8218-4815-9.
@@ -76,37 +76,37 @@
76
76
 
77
77
  > 用 `../gpu-friendly-math.md` 的**八维记分卡**逐项评判。微分几何最大的坑是"度量 / 曲率矩阵的求逆与物化"。
78
78
 
79
- - **维度 2/3(GEMM 可映射 / 复杂度)—— 求逆是生死线。** 朴素自然梯度要算 N×N Fisher 的逆,N 是参数量(~10⁹),O(N³) 求逆 + O(N²) 显存,**直接出局**。
80
- - **可改造 ✅**:**K-FAC** 把 F 分块为 Kronecker 积 A⊗B,利用 (A⊗B)⁻¹ = A⁻¹⊗B⁻¹,只需对两个小因子求逆,且预条件作用到梯度上**就是 GEMM**。这就是"能否 Kronecker 因子化为 GEMM"的肯定答案——能,且这是它唯一可上集群的形态。
81
- - **维度 4(显存)—— 不要物化全 Hessian / 全曲率张量。** Riemann 曲率张量是 4 阶,全物化爆显存。用 **Hessian-vector product(HVP)** 经一次反向以 O(N) 拿到曲率信息,避免 N×N。
82
- - **维度 5(低精度)—— Fisher / 度量矩阵常病态。** bf16/fp16 下求逆灾难性放大误差,**必须加阻尼(damping / Tikhonov,F+λI)** 并把求逆留在 fp32;否则违反"低精度稳定"。
83
- - **维度 6(并行)—— 平行移动 / 测地线是串行 ODE。** 沿曲线积分联络方程是长串行递推,并行性差;工程上用**一步 retraction / 闭式平行移动**(特定流形有解析公式)替代逐步积分。
84
- - **维度 1/2(张量化 / GEMM)—— 群卷积可友好,但连续群要当心。** 离散群(如 C_n、八面体群)的群卷积可展开成 GEMM ✅;连续李群需采样离散化,采样不当会导致等变性破缺 + 不规则 gather/scatter(维度 7 稀疏不友好)。
79
+ - **D2/D3**:求逆是生死线。 朴素自然梯度要算 N×N Fisher 的逆,N 是参数量(~10⁹),O(N³) 求逆 + O(N²) 显存,**直接出局**。
80
+ - **可改造 [v]**:**K-FAC** 把 F 分块为 Kronecker 积 A⊗B,利用 (A⊗B)⁻¹ = A⁻¹⊗B⁻¹,只需对两个小因子求逆,且预条件作用到梯度上**就是 GEMM**。这就是"能否 Kronecker 因子化为 GEMM"的肯定答案——能,且这是它唯一可上集群的形态。
81
+ - **D4**:不要物化全 Hessian / 全曲率张量。 Riemann 曲率张量是 4 阶,全物化爆显存。用 **Hessian-vector product(HVP)** 经一次反向以 O(N) 拿到曲率信息,避免 N×N。
82
+ - **D5**:Fisher / 度量矩阵常病态。 bf16/fp16 下求逆灾难性放大误差,**必须加阻尼(damping / Tikhonov,F+λI)** 并把求逆留在 fp32;否则违反"低精度稳定"。
83
+ - **D6**:平行移动 / 测地线是串行 ODE 沿曲线积分联络方程是长串行递推,并行性差;工程上用**一步 retraction / 闭式平行移动**(特定流形有解析公式)替代逐步积分。
84
+ - **D1/D2**:群卷积可友好,但连续群要当心。 离散群(如 C_n、八面体群)的群卷积可展开成 GEMM [v];连续李群需采样离散化,采样不当会导致等变性破缺 + 不规则 gather/scatter(D7 稀疏不友好)。
85
85
 
86
86
  **自然梯度 / K-FAC 八维记分卡(worked example):**
87
87
 
88
- | 维度 | 朴素自然梯度(全 Fisher 求逆)| K-FAC(Kronecker 因子化)|
88
+ | D | 朴素自然梯度(全 Fisher 求逆)| K-FAC(Kronecker 因子化)|
89
89
  |------|------------------------------|--------------------------|
90
- | 1 张量化 | 大矩阵显式逆 | 批量小矩阵代数 |
91
- | 2 GEMM | N×N 求逆无法 GEMM | A⁻¹⊗B⁻¹ 作用 = GEMM 链 |
92
- | 3 复杂度 | O(N³) | 两个小因子,亚立方 |
93
- | 4 显存 | 物化 N×N | 只存两个小因子 |
94
- | 5 低精度 | 病态、需 fp64 | ⚠️ 加阻尼 + fp32 求逆可改造 |
95
- | 6 并行 | ⚠️ 单次大求逆难并行 | 各层因子独立、可并行 |
96
- | 7 稀疏 | — | 块对角结构化 |
97
- | 8 融合 | | 预条件可融进优化器 kernel |
90
+ | D1 | [x] 大矩阵显式逆 | [v] 批量小矩阵代数 |
91
+ | D2 | [x] N×N 求逆无法 GEMM | [v] A⁻¹⊗B⁻¹ 作用 = GEMM 链 |
92
+ | D3 | [x] O(N³) | [v] 两个小因子,亚立方 |
93
+ | D4 | [x] 物化 N×N | [v] 只存两个小因子 |
94
+ | D5 | [x] 病态、需 fp64 | [~] 加阻尼 + fp32 求逆可改造 |
95
+ | D6 | [~] 单次大求逆难并行 | [v] 各层因子独立、可并行 |
96
+ | D7 | — | [v] 块对角结构化 |
97
+ | D8 | [x] | [v] 预条件可融进优化器 kernel |
98
98
 
99
99
  **结论**:黎曼 / 信息几何方法**只有在度量被结构化因子化(Kronecker / 块对角 / 低秩)后才 GPU 可行**;精确求逆与精确平行移动都属于"美但不可算",须改造或淘汰。
100
100
 
101
101
  ## 该调用哪个思想透镜
102
102
 
103
- - **symmetry(⚛️ 对称与不变性)—— 首选。** 规范等变、李群对称、纤维丛 = 把"frame / 坐标选择无关"编码成对称性,是本书与 DL 最强的接口。
104
- - **optimization(⚖️ 优化)—— 并列首选。** 自然梯度、Riemannian SGD、曲率正则都是"在弯曲约束空间里找最优"。
105
- - **transformation(🔄 变换)**:指数 / 对数映射、retraction、坐标变换简化问题。
106
- - **modeling(🌉 建模)**:把参数 / 数据空间显式建模为流形,再翻译回算法。
107
- - **topological-thinking(🌀 拓扑)**:辅助——de Rham 上同调 / 整体不变量用于守恒量与可积性诊断。
103
+ - **symmetry(对称与不变性)—— 首选。** 规范等变、李群对称、纤维丛 = 把"frame / 坐标选择无关"编码成对称性,是本书与 DL 最强的接口。
104
+ - **variational(变分)—— 并列首选。** 自然梯度、Riemannian SGD、曲率正则都是"在弯曲约束空间里找最优"。
105
+ - **duality(对偶)**:指数 / 对数映射、retraction、坐标变换简化问题。
106
+ - **geometric(几何)**:把参数 / 数据空间显式建模为流形,再翻译回算法。
107
+ - **topological(拓扑)**:辅助——de Rham 上同调 / 整体不变量用于守恒量与可积性诊断。
108
108
 
109
- 组合建议:先 `symmetry` 定对称结构 → `optimization` 落到自然梯度 / Riemannian 优化 → `duality` 处理 retraction → 过 `../gpu-friendly-math.md` 验收门。
109
+ 组合建议:先 `symmetry` 定对称结构 → `variational` 落到自然梯度 / Riemannian 优化 → `duality` 处理 retraction → 过 `../gpu-friendly-math.md` 验收门。
110
110
 
111
111
  ## 反模式
112
112
 
@@ -127,7 +127,7 @@
127
127
 
128
128
  ## 深挖入口
129
129
 
130
- > **📖 书目信息**:Jeffrey M. Lee, *Manifolds and Differential Geometry*, Graduate Studies in Mathematics Vol. 107, American Mathematical Society, 2009. ISBN 978-0-8218-4815-9.
130
+ > **书目信息**:Jeffrey M. Lee, *Manifolds and Differential Geometry*, Graduate Studies in Mathematics Vol. 107, American Mathematical Society, 2009. ISBN 978-0-8218-4815-9.
131
131
  >
132
132
  > **启用方式**:将 `Manifolds and Differential Geometry.pdf` 放入项目根目录的 `math_book/` 文件夹,Agent 即可自动搜索原文。PDF 不随 npm/git 分发(版权原因),需自行获取。
133
133
 
@@ -0,0 +1,146 @@
1
+ # Matrix Analysis
2
+
3
+ > Roger A. Horn & Charles R. Johnson, *Matrix Analysis*, 2nd Edition, Cambridge University Press, 2013 (ISBN 978-0-521-83940-2). A graduate-level classic of matrix theory unified by the theme of **canonical forms**.
4
+
5
+ ## Overview
6
+
7
+ This is the authoritative reference for upgrading "linear algebra" to "matrix analysis": not just computing with matrices, but studying invariants under **similarity / unitary equivalence / congruence** transformations, canonical forms, eigenvalue location and perturbation, norm geometry, and positive-definite/nonnegative structures. For AI/ML/GPU, it is the **backbone closest to the hardware-level operators** in the v2 reading list -- GEMM, numerical stability, low-rank compression, and second-order optimization all trace their roots here.
8
+
9
+ Actual chapter map (from the table of contents):
10
+
11
+ - **Ch 0 Review and Miscellanea**: rank, nonsingularity, inner products, block matrices -- quick-reference foundation.
12
+ - **Ch 1 Eigenvalues, Eigenvectors, and Similarity**: characteristic equations, characteristic polynomials, algebraic/geometric multiplicity, similarity (Sec. 1.1-1.4).
13
+ - **Ch 2 Unitary Similarity and Unitary Equivalence**: QR decomposition (Sec. 2.1), Schur triangularization (Sec. 2.4), normal matrices (Sec. 2.5), **SVD (Sec. 2.6)**, CS decomposition (Sec. 2.7).
14
+ - **Ch 3 Canonical Forms for Similarity and Triangular Factorizations**: Jordan canonical form (Sec. 3.1), minimal polynomials and companion matrices (Sec. 3.3), real Jordan and Weyr forms (Sec. 3.4), triangular factorization LU (Sec. 3.5).
15
+ - **Ch 4 Hermitian, Symmetric Matrices, and Congruences**: variational characterization Courant-Fischer (Sec. 4.2), eigenvalue inequalities Weyl/interlacing (Sec. 4.3), congruences and Sylvester's law of inertia (Sec. 4.5).
16
+ - **Ch 5 Norms for Vectors and Matrices**: norms and inner products, dual norms (Sec. 5.5), **matrix norms (Sec. 5.6-5.7)**, **condition numbers (Sec. 5.8)**.
17
+ - **Ch 6 Location and Perturbation of Eigenvalues**: Gershgorin discs (Sec. 6.1-6.2), eigenvalue perturbation theorems (Sec. 6.3).
18
+ - **Ch 7 Positive Definite and Semidefinite Matrices**: polar decomposition and SVD (Sec. 7.3-7.4), **Schur product theorem (Sec. 7.5)**, simultaneous diagonalization (Sec. 7.6), Loewner partial order and block matrices (Sec. 7.7), positive-definite inequalities (Sec. 7.8).
19
+ - **Ch 8 Positive and Nonnegative Matrices**: Perron-Frobenius (Sec. 8.2-8.5), stochastic and doubly stochastic matrices (Sec. 8.7).
20
+ - Appendices A-F: complex numbers, **convex sets and functions (B)**, fundamental theorem of algebra, eigenvalue continuity, compactness, canonical pairs (F).
21
+
22
+ **Boundary reminder for activation**: this book is **theory-first** -- addressing existence, characterizations, inequalities, and canonical forms, **not numerical algorithm recipes**. Specific algorithm implementations, convergence constants, and stability details (e.g., communication lower bounds for blocked QR, actual complexity coefficients for SVD) require a companion numerical linear algebra textbook (Golub-Van Loan / Trefethen-Bau). What is provided here is an **activation index** for "which structure to use + why + can the GPU compute it"; for implementation details, consult those books.
23
+
24
+ ## Core Structures Transferable to AI/Infra
25
+
26
+ | Mathematical structure (chapter) | Transfer to ML / algorithms / Infra |
27
+ |---|---|
28
+ | **SVD / low-rank (Sec. 2.6, 7.4)** | The foundation of all low-rank compression: LoRA, PCA/whitening, Eckart-Young optimal low-rank approximation, KV-Cache low-rank reduction, weight compression |
29
+ | **Spectrum and similarity invariants (Ch 1)** | Hessian/gradient covariance spectra, spectral radius determines stability of linear attention / SSM / RNN, trace = parameter counting / regularization |
30
+ | **Schur triangularization + normal matrices (Sec. 2.4-2.5)** | Foundation for numerical EVD algorithms (QR algorithm); normal <=> unitarily diagonalizable, the criterion for "well-behaved spectra" |
31
+ | **Variational characterization Courant-Fischer (Sec. 4.2)** | Rayleigh quotients, spectral normalization, spectral clustering, PCA as min-max; largest singular value = operator norm |
32
+ | **Eigenvalue perturbation Weyl/Bauer-Fike (Sec. 4.3, 6.3)** | Spectral shift bounds under quantization/low-precision/pruning, training perturbation robustness, stability certificates |
33
+ | **Matrix norms + duality (Sec. 5.5-5.7)** | Spectral norm (gradient clipping / Lipschitz), Frobenius (weight decay), **nuclear norm = dual of spectral norm** (low-rank regularization) |
34
+ | **Condition numbers (Sec. 5.8)** | Numerical stability diagnostics, preconditioning, why bf16 training diverges |
35
+ | **Polar decomposition + Newton-Schulz (Sec. 7.3)** | Orthogonalizing gradients/weights (Muon optimizer, orthogonal initialization), computable with pure GEMM |
36
+ | **Positive definiteness / PSD (Ch 7)** | Kernel methods, covariances, attention Gram matrices, second-order method preconditioners, Loewner partial order for matrix inequalities |
37
+ | **Schur product theorem (Sec. 7.5)** | Hadamard products preserve PSD -- learnable kernel engineering, gating that does not destroy positive-definite structure |
38
+ | **Perron-Frobenius / stochastic matrices (Ch 8)** | Row-stochastic attention mixing and collapse (over-smoothing), PageRank, graph propagation, spectral gap = expressivity |
39
+
40
+ The table above is organized into four **activation families** for convenient retrieval:
41
+
42
+ - **Spectral family (Ch 1-3)**: eigenvalues / similarity / canonical forms -- answering "is the dynamics stable, what does the spectrum look like." Note that Jordan/Weyr forms are theoretical tools; numerically one turns to Schur/SVD.
43
+ - **Norm family (Ch 5-6)**: norms / duality / condition numbers / perturbation -- answering "how do errors propagate, is low precision stable, should we precondition."
44
+ - **Positive-definite family (Ch 4, 7)**: Hermitian / PSD / polar decomposition / Loewner -- answering "second-order structure, kernels, covariances, nearest orthogonal matrix."
45
+ - **Nonnegative family (Ch 8)**: Perron-Frobenius / stochastic matrices -- answering "propagation, mixing, collapse, stationary distributions."
46
+
47
+ ## Key Bridging Facts (Activation Shorthand)
48
+
49
+ When "activating" this book into algorithms, these are the most frequently used connecting facts -- memorizing them enables rapid navigation between structures:
50
+
51
+ - **Condition number kappa_2(A) = sigma_max / sigma_min (Sec. 5.8)**: directly predicts how many orders of magnitude errors are amplified under bf16/fp8.
52
+ - **SVD <=> eigendecomposition of A^H A and A A^H, sigma = sqrt(lambda) (Sec. 2.6, 7.4)**: singular values are the square roots of the Gram matrix eigenvalues.
53
+ - **Spectral norm = sigma_max, Frobenius = sqrt(Sum sigma^2), nuclear norm = Sum sigma (Sec. 5.6)**: all three major matrix norms are determined entirely by singular values; spectral norm and nuclear norm are dual to each other.
54
+ - **Normal matrices <=> unitarily diagonalizable (Sec. 2.5)**: the only class where "eigenvalue = singular value structure is well-conditioned"; for non-normal matrices one must look at pseudospectra.
55
+ - **Positive definite <=> all eigenvalues > 0 <=> all leading principal minors > 0 (Sec. 7.1)**: the latter is a computable positive-definiteness test (Sylvester's criterion).
56
+ - **Polar decomposition A = UP, P = (A^H A)^{1/2} (Sec. 7.3)**: Newton-Schulz iteration converges to the orthogonal factor U.
57
+ - **Weyl perturbation bound |lambda_i(A+E) - lambda_i(A)| <= ||E||_2 (Sec. 4.3)**: one line gives the spectral shift upper bound for quantization/pruning.
58
+ - **Row-stochastic matrix spectral radius = 1 (Sec. 8.7)**: the Perron root of attention is always 1; the spectral gap determines the collapse rate.
59
+
60
+ ## Problem Types Suited for Activation
61
+
62
+ - **Low-rank / compression**: where is the redundancy in attention, KV-Cache, weights, gradients? How low can the rank go? How to estimate the optimal approximation error from truncation (Eckart-Young)? Should low-rank regularization use the nuclear norm or explicit parameterization?
63
+ - **Numerical stability**: why does low-precision (bf16/fp8) training diverge? How to monitor condition numbers and spectral radii online during training? Are there bounds on spectral shifts from quantization/pruning (Weyl, Bauer-Fike)? Which operators need reparameterization for stability?
64
+ - **Spectral design**: the operator norms behind normalization (spectral normalization / BatchNorm); spectral radius constraints for recurrent / state-space models (SSM); spectral gap determines expressivity and separability.
65
+ - **Second-order optimization**: PSD structure and negative curvature of Hessian / Fisher (inertia law for detecting saddle points); condition number improvement via preconditioners; Kronecker-factor approximations (K-FAC / Shampoo).
66
+ - **Graphs / propagation**: stability and over-smoothing of message passing; mixing time of row-stochastic operators; Markov chain stationary distributions and spectral gaps.
67
+
68
+ ## Possible Algorithmic Inspirations
69
+
70
+ > Each item is tagged with the **eight-dimension touchpoint** (corresponding to the dimension numbers in `../gpu-friendly-math.en.md`) for direct entry into the GPU acceptance gate.
71
+
72
+ 1. **Randomized numerical linear algebra (randomized NLA)**: using random projections + QR (Sec. 2.1) for randomized SVD, reducing the O(n^3) full decomposition to sub-quadratic, producing low-rank sketches of very large weights/activations. *Touchpoint: D2/D3 -- all GEMM, manageable complexity.*
73
+ 2. **Low-rank attention / KV compression**: using Eckart-Young (Sec. 7.4) to guarantee truncated SVD is the optimal low-rank approximation; using the **nuclear norm (dual of spectral norm, Sec. 5.5)** as low-rank regularization, projecting the KV-Cache into a low-dimensional subspace. *Touchpoint: D2/D4 -- GEMM chains + memory compression.*
74
+ 3. **Spectral normalization**: power iteration to estimate the largest singular value (operator norm, Sec. 5.6), constraining per-layer Lipschitz constants -- GANs/diffusion/stable training. *Touchpoint: D1/D6 -- matvec, but serial iteration requires blocking.*
75
+ 4. **Newton-Schulz orthogonalization (Muon-style)**: polar decomposition (Sec. 7.3) projects gradient matrices onto the nearest orthogonal matrix, with iterations involving only matrix multiplications -- currently the most GPU-friendly "second-order-flavored" update. *Touchpoint: D2/D6/D8 -- pure GEMM, fusible, bf16-stable.*
76
+ 5. **Preconditioning / Shampoo / K-FAC**: condition numbers (Sec. 5.8) diagnose ill-conditioning, using PSD Kronecker factors (Ch 7) to approximate the Hessian for preconditioning, rounding out ill-conditioned loss landscapes. *Touchpoint: D2/D5 -- small-matrix GEMM, watch precision for inverse operations.*
77
+ 6. **Gershgorin cheap spectral radius gate (Sec. 6.1)**: using the disc bound O(n^2) in the training loop to quickly estimate the spectral radius as a low-cost stability gate, without running a full EVD. *Touchpoint: D1/D3 -- per-row summation, extremely cheap.*
78
+ 7. **PSD kernel engineering (Schur product theorem, Sec. 7.5)**: composing multiple PSD kernels via Hadamard products, guaranteeing that learnable similarity matrices remain positive semidefinite. *Touchpoint: D1 -- element-wise tensor products, naturally friendly.*
79
+ 8. **Perron-Frobenius diagnostics (Sec. 8.2-8.5)**: treating row-stochastic attention as a Markov operator, using the spectral gap to quantify over-smoothing / rank collapse, guiding residual and temperature design. *Touchpoint: D1/D3 -- cheap spectral estimation, avoids deep-layer collapse.*
80
+ 9. **Blocked / communication-avoiding decompositions**: writing QR, Cholesky (Sec. 3.5) in blocked versions, replacing column-by-column elimination with GEMM, reducing communication rounds across devices. *Touchpoint: D2/D6 -- reforming serial recurrences into parallelism + overlap.*
81
+
82
+ ## GPU Friendliness Warning
83
+
84
+ > The scoring dimensions reference the **eight-dimension checklist** in `../gpu-friendly-math.en.md` (Tensorization / GEMM-mappability / Complexity / Memory / Low-precision / Parallelism / Sparsity / Operator fusion); definitions are not repeated here.
85
+
86
+ **Natively friendly (math beautiful x GPU friendly):**
87
+ - **Truncated SVD / low-rank**: expressed as GEMM chains (D2), compressing KV-Cache/weights (D4).
88
+ - **Frobenius / spectral norms, Gram matrices, Hadamard products**: batched tensor algebra (D1, D2).
89
+ - **Polar decomposition Newton-Schulz**: pure matrix-multiplication iteration (D2, D6, D8 fusible), robust under bf16.
90
+ - **Gershgorin discs**: O(n^2) per-row summation (D1), cheap stability estimation.
91
+ - **Well-conditioned PSD blocked Cholesky / Gram construction**: blocked form yields GEMM chains (D2), commonly used in kernel methods and covariance preconditioning.
92
+
93
+ **Beautiful but not computable:**
94
+ - **Jordan canonical form (Sec. 3.1)** -- the classic counter-example: eigenvalue multiplicities are extremely sensitive to perturbation, fundamentally unreliable under floating-point, **never use as a numerical tool** (violates D5 low-precision stability). Weyr form has the same issue.
95
+ - **Full EVD / SVD at O(n^3)** -- blows up for large matrices (violates D3), must switch to randomized/iterative methods.
96
+ - **Non-normal matrices (Sec. 2.5 and beyond)** -- eigenvalues do not reflect true behavior, pseudospectra are needed; spectral distortion under low precision (D5).
97
+ - **Ill-conditioned / high condition number (Sec. 5.8)** -- catastrophic cancellation occurs, requiring fp64 for correctness, conflicting with bf16/fp8 training (D5).
98
+ - **Serial dependencies in QR / Cholesky (Sec. 2.1, 3.5)** -- naive implementations are long serial recurrences (violates D6), requiring blocked / communication-avoiding variants.
99
+ - **Serial iteration in power iteration** -- single-vector iteration has low parallelism; must be blocked (block / subspace iteration) to saturate SMs (D6).
100
+
101
+ **Reform strategies (echoing the Make-It-Computable Toolkit in `../gpu-friendly-math.en.md`):**
102
+ - Full EVD/SVD -> **randomized + truncated** to reduce complexity (D3);
103
+ - Exact decompositions -> **blocked / GEMM-ified** to eliminate serial dependencies (D2/D6);
104
+ - Ill-conditioned/non-normal -> **reparameterization + spectral normalization** to stabilize low precision (D5);
105
+ - Non-computable canonical forms like Jordan -> retain only for **theoretical proofs**, numerically switch to Schur/SVD.
106
+
107
+ ## Which Design Lens to Invoke
108
+
109
+ Used in conjunction with the design lenses in `../../lenses/`:
110
+
111
+ - **`duality`**: similarity / unitary equivalence / congruence, SVD, diagonalization -- the soul of this book is "change coordinates to reveal structure."
112
+ - **`algorithmic`**: power iteration, Newton-Schulz, QR algorithm, randomized NLA -- turning theorems into runnable kernels.
113
+ - **`variational`**: variational characterizations (Sec. 4.2), condition numbers and preconditioning, second-order methods, matrix inequalities under the Loewner partial order.
114
+ - **`symmetry`**: unitary invariance, similarity invariants (eigenvalues/trace/determinant), well-conditioned spectra of normal matrices.
115
+ - **`categorical`**: canonical forms as "representatives of equivalence classes" -- capturing essence through the simplest morphology, ignoring coordinate details.
116
+ - **`probabilistic`**: randomized NLA, random matrix spectra, Perron-Frobenius / Markov chain stationary distributions.
117
+
118
+ ## Anti-patterns
119
+
120
+ - **Using Jordan form as a numerical algorithm**: it is not computable under floating-point, only useful for theoretical analysis; do not put it into a kernel.
121
+ - **Defaulting to full SVD/EVD**: in large-scale settings one should use randomized/truncated/iterative methods, otherwise O(n^3) will bog everything down.
122
+ - **Looking only at eigenvalues while ignoring non-normality**: eigenvalues of non-normal matrices do not predict transient behavior; look at singular values / pseudospectra instead.
123
+ - **Assuming all matrices are well-conditioned**: deploying bf16/fp8 without monitoring condition numbers, then debugging after divergence.
124
+ - **Using the nuclear norm while forgetting it requires SVD**: the nuclear norm is an elegant low-rank regularizer, but its computation depends on SVD, requiring proximal/randomized techniques.
125
+ - **Assuming exact positive definiteness numerically**: under floating-point, Gram/covariance matrices can lose positive definiteness; add jitter (diagonal perturbation) or use pivoted Cholesky.
126
+ - **Using Frobenius norm as a low-rank regularizer**: Frobenius / weight decay suppresses "energy" not "rank"; for low rank, use the nuclear norm or explicit low-rank parameterization (e.g., LoRA).
127
+ - **Discussing "eigenvalue magnitudes" for non-symmetric matrices**: when measuring energy/norm/stability margins, look at **singular values**; the modulus of eigenvalues of non-normal matrices is seriously misleading (transient growth far exceeds what the spectral radius predicts).
128
+ - **Materializing the full O(n^2) Gram matrix**: attention/kernel matrices without blocking will blow up memory; use FlashAttention-style fusion + blocking (echoing GPU dimensions D4/D8).
129
+ - **Stacking theorems without diagnosing the bottleneck**: first ask "is the algorithmic bottleneck spectral, low-rank, or stability," then select the structure; do not dump matrix theory upfront.
130
+
131
+ ## Deep Dive Entry
132
+
133
+ > **Bibliographic info**: Roger A. Horn & Charles R. Johnson, *Matrix Analysis*, 2nd Edition, Cambridge University Press, 2013. ISBN 978-0-521-83940-2.
134
+ >
135
+ > **Activation method**: Place `Matrix Analysis.pdf` in the `math_book/` folder at the project root; the Agent can then automatically search the original text. The PDF is not distributed via npm/git (copyright reasons); obtain it independently.
136
+
137
+ **Full-fidelity lookup = have the Agent automatically search the local PDF `math_book/Matrix Analysis.pdf`**: extract with `pdftotext` -> `grep` to locate keywords/theorem names -> `Read` the relevant pages for close study. This file is an "activation index," not a substitute; when precise statements, proofs, or constants are needed, go back to the original book.
138
+
139
+ Actual chapters worth deep reading:
140
+
141
+ - **Sec. 2.6 The singular value decomposition** -- the origin of all low-rank compression / LoRA / PCA.
142
+ - **Sec. 4.2-4.3 Variational characterizations & eigenvalue inequalities** -- Courant-Fischer min-max and Weyl inequalities, the theoretical roots of spectral normalization and perturbation bounds.
143
+ - **Sec. 5.6-5.8 Matrix norms & condition numbers** -- all the criteria for numerical stability, gradient clipping, and preconditioning are here.
144
+ - **Sec. 7.3-7.5 Polar/SVD & the Schur product theorem** -- the direct source for Muon orthogonalization and PSD kernel engineering.
145
+ - **Sec. 6.1-6.3 Gershgorin discs & perturbation theorems** -- cheap spectral localization and perturbation robustness.
146
+ - **Sec. 8.2-8.5 Perron-Frobenius theory** -- row-stochastic attention, graph propagation, over-smoothing analysis.
@@ -1,4 +1,4 @@
1
- # 🧮 矩阵分析 / Matrix Analysis
1
+ # 矩阵分析 / Matrix Analysis
2
2
 
3
3
  > Roger A. Horn & Charles R. Johnson, *Matrix Analysis*, 2nd Edition, Cambridge University Press, 2013(ISBN 978-0-521-83940-2)。以**标准型(canonical forms)作为统一主题**的研究生级矩阵理论经典。
4
4
 
@@ -69,51 +69,51 @@
69
69
 
70
70
  > 每条标注**八维落点**(对应 `../gpu-friendly-math.md` 维度编号),方便直接进 GPU 验收门。
71
71
 
72
- 1. **随机化数值线代(randomized NLA)**:用随机投影 + QR(§2.1)做随机 SVD,把 O(n³) 完整分解降到亚二次,对超大权重/激活做低秩草图(sketching)。*落点:维度 2/3——全 GEMM、复杂度可控。*
73
- 2. **低秩注意力 / KV 压缩**:以 Eckart–Young(§7.4)保证截断 SVD 是最优低秩逼近;用**核范数(谱范数对偶,§5.5)**作低秩正则,把 KV-Cache 投影到低维子空间。*落点:维度 2/4——GEMM 链 + 显存压缩。*
74
- 3. **谱归一化(spectral normalization)**:power iteration 估最大奇异值(算子范数 §5.6),约束每层 Lipschitz——GAN/扩散/稳定训练。*落点:维度 1/6——matvec,但迭代串行需块化。*
75
- 4. **Newton–Schulz 正交化(Muon 式)**:极分解(§7.3)把梯度矩阵投到最近正交矩阵,迭代只含矩阵乘——当前最 GPU 友好的"二阶味"更新。*落点:维度 2/6/8——纯 GEMM、可融合、bf16 稳。*
76
- 5. **预条件 / Shampoo / K-FAC**:条件数(§5.8)诊断病态,用 PSD Kronecker 因子(Ch 7)近似 Hessian 做预条件,把病态损失面拉圆。*落点:维度 2/5——小矩阵 GEMM,注意逆运算的精度。*
77
- 6. **Geršgorin 廉价谱半径门(§6.1)**:训练循环里用圆盘界 O(n²) 快速估谱半径,做低成本稳定性 gate,不必跑完整 EVD。*落点:维度 1/3——逐行求和,极廉价。*
78
- 7. **PSD 核工程(Schur 积定理 §7.5)**:用 Hadamard 积组合多个 PSD 核,保证可学习相似度矩阵始终半正定。*落点:维度 1——逐元素张量积,天然友好。*
79
- 8. **Perron–Frobenius 诊断(§8.2–8.5)**:把行随机 attention 当 Markov 算子,用谱 gap 量化 over-smoothing / rank collapse,指导残差与温度设计。*落点:维度 1/3——谱估计廉价,避免深层坍缩。*
80
- 9. **块化 / communication-avoiding 分解**:把 QR、Cholesky(§3.5)写成分块版本,用 GEMM 替代逐列消元,跨设备减少通信轮次。*落点:维度 2/6——串行递推改造成并行 + overlap。*
72
+ 1. **随机化数值线代(randomized NLA)**:用随机投影 + QR(§2.1)做随机 SVD,把 O(n³) 完整分解降到亚二次,对超大权重/激活做低秩草图(sketching)。*落点:D2/D3——全 GEMM、复杂度可控。*
73
+ 2. **低秩注意力 / KV 压缩**:以 Eckart–Young(§7.4)保证截断 SVD 是最优低秩逼近;用**核范数(谱范数对偶,§5.5)**作低秩正则,把 KV-Cache 投影到低维子空间。*落点:D2/D4——GEMM 链 + 显存压缩。*
74
+ 3. **谱归一化(spectral normalization)**:power iteration 估最大奇异值(算子范数 §5.6),约束每层 Lipschitz——GAN/扩散/稳定训练。*落点:D1/D6——matvec,但迭代串行需块化。*
75
+ 4. **Newton–Schulz 正交化(Muon 式)**:极分解(§7.3)把梯度矩阵投到最近正交矩阵,迭代只含矩阵乘——当前最 GPU 友好的"二阶味"更新。*落点:D2/D6/D8——纯 GEMM、可融合、bf16 稳。*
76
+ 5. **预条件 / Shampoo / K-FAC**:条件数(§5.8)诊断病态,用 PSD Kronecker 因子(Ch 7)近似 Hessian 做预条件,把病态损失面拉圆。*落点:D2/D5——小矩阵 GEMM,注意逆运算的精度。*
77
+ 6. **Geršgorin 廉价谱半径门(§6.1)**:训练循环里用圆盘界 O(n²) 快速估谱半径,做低成本稳定性 gate,不必跑完整 EVD。*落点:D1/D3——逐行求和,极廉价。*
78
+ 7. **PSD 核工程(Schur 积定理 §7.5)**:用 Hadamard 积组合多个 PSD 核,保证可学习相似度矩阵始终半正定。*落点:D1——逐元素张量积,天然友好。*
79
+ 8. **Perron–Frobenius 诊断(§8.2–8.5)**:把行随机 attention 当 Markov 算子,用谱 gap 量化 over-smoothing / rank collapse,指导残差与温度设计。*落点:D1/D3——谱估计廉价,避免深层坍缩。*
80
+ 9. **块化 / communication-avoiding 分解**:把 QR、Cholesky(§3.5)写成分块版本,用 GEMM 替代逐列消元,跨设备减少通信轮次。*落点:D2/D6——串行递推改造成并行 + overlap。*
81
81
 
82
82
  ## GPU 友好性警告
83
83
 
84
84
  > 评分维度引用 `../gpu-friendly-math.md` 的**八维检查**(张量化 / GEMM 可映射 / 复杂度 / 显存 / 低精度 / 并行 / 稀疏 / 算子融合),此处不重复定义。
85
85
 
86
86
  **天然友好(math beautiful × GPU friendly):**
87
- - **SVD 截断 / 低秩**:写成 GEMM 链(维度 2),压缩 KV-Cache/权重(维度 4)。
88
- - **Frobenius / 谱范数、Gram 矩阵、Hadamard 积**:批量张量代数(维度 1、2)。
89
- - **极分解 Newton–Schulz**:纯矩阵乘迭代(维度 2、6、8 可融合),bf16 下稳健。
90
- - **Geršgorin 圆盘**:O(n²) 逐行求和(维度 1),廉价稳定性估计。
91
- - **良态 PSD 的 blocked Cholesky / Gram 构造**:分块后是 GEMM 链(维度 2),核方法与协方差预条件常用。
87
+ - **SVD 截断 / 低秩**:写成 GEMM 链(D2),压缩 KV-Cache/权重(D4)。
88
+ - **Frobenius / 谱范数、Gram 矩阵、Hadamard 积**:批量张量代数(D1/D2)。
89
+ - **极分解 Newton–Schulz**:纯矩阵乘迭代(D2/D6/D8 可融合),bf16 下稳健。
90
+ - **Geršgorin 圆盘**:O(n²) 逐行求和(D1),廉价稳定性估计。
91
+ - **良态 PSD 的 blocked Cholesky / Gram 构造**:分块后是 GEMM 链(D2),核方法与协方差预条件常用。
92
92
 
93
93
  **美但不可算(beautiful, not computable):**
94
- - **Jordan 标准型(§3.1)**——经典反例:特征值重数对扰动极度敏感,浮点下根本无法可靠计算,**永远不要当数值工具**(违反维度 5 低精度稳定)。Weyr 型同理。
95
- - **完整 EVD / SVD 的 O(n³)**——大矩阵直接爆(违反维度 3),必须换随机化/迭代法。
96
- - **非正规矩阵(non-normal,§2.5 之外)**——特征值不能反映真实行为,需 pseudospectra;低精度下谱失真(维度 5)。
97
- - **病态 / 高条件数(§5.8)**——会出现灾难性抵消,要 fp64 才对,与 bf16/fp8 训练冲突(维度 5)。
98
- - **QR / Cholesky 的串行依赖(§2.1, §3.5)**——朴素实现是长串行递推(违反维度 6),需 blocked / communication-avoiding 变体。
99
- - **power iteration 的串行迭代**——单向量迭代并行度低;需块化(block / subspace iteration)才吃满 SM(维度 6)。
94
+ - **Jordan 标准型(§3.1)**——经典反例:特征值重数对扰动极度敏感,浮点下根本无法可靠计算,**永远不要当数值工具**(违反 D5)。Weyr 型同理。
95
+ - **完整 EVD / SVD 的 O(n³)**——大矩阵直接爆(违反 D3),必须换随机化/迭代法。
96
+ - **非正规矩阵(non-normal,§2.5 之外)**——特征值不能反映真实行为,需 pseudospectra;低精度下谱失真(D5)。
97
+ - **病态 / 高条件数(§5.8)**——会出现灾难性抵消,要 fp64 才对,与 bf16/fp8 训练冲突(D5)。
98
+ - **QR / Cholesky 的串行依赖(§2.1, §3.5)**——朴素实现是长串行递推(违反 D6),需 blocked / communication-avoiding 变体。
99
+ - **power iteration 的串行迭代**——单向量迭代并行度低;需块化(block / subspace iteration)才吃满 SM(D6)。
100
100
 
101
101
  **改造手法(呼应 `../gpu-friendly-math.md` 的 Make-It-Computable Toolkit):**
102
- - 完整 EVD/SVD → **随机化 + 截断**降复杂度(维度 3);
103
- - 精确分解 → **块化 / GEMM 化**消除串行(维度 2/6);
104
- - 病态/非正规 → **重参数化 + 谱归一化**稳低精度(维度 5);
102
+ - 完整 EVD/SVD → **随机化 + 截断**降复杂度(D3);
103
+ - 精确分解 → **块化 / GEMM 化**消除串行(D2/D6);
104
+ - 病态/非正规 → **重参数化 + 谱归一化**稳低精度(D5);
105
105
  - Jordan 等不可算标准型 → 只留作**理论证明**,数值上换 Schur/SVD。
106
106
 
107
107
  ## 该调用哪个思想透镜
108
108
 
109
- 配合 `skills/` 下的现有武器使用:
109
+ 配合 `../../lenses/` 下的思想透镜使用:
110
110
 
111
- - **`duality`(变换)**:相似 / 酉等价 / 合同、SVD、对角化——本书的灵魂就是"换坐标让结构显形"。
112
- - **`algorithmic-thinking`(算法与计算)**:power iteration、Newton–Schulz、QR algorithm、随机化 NLA——把定理变成可跑的 kernel。
113
- - **`optimization`(优化)**:变分刻画(§4.2)、条件数与预条件、二阶法、Loewner 偏序下的矩阵不等式。
111
+ - **`duality`(对偶)**:相似 / 酉等价 / 合同、SVD、对角化——本书的灵魂就是"换坐标让结构显形"。
112
+ - **`algorithmic`(算法)**:power iteration、Newton–Schulz、QR algorithm、随机化 NLA——把定理变成可跑的 kernel。
113
+ - **`variational`(变分)**:变分刻画(§4.2)、条件数与预条件、二阶法、Loewner 偏序下的矩阵不等式。
114
114
  - **`symmetry`(对称与不变性)**:酉不变性、相似不变量(特征值/迹/行列式)、正规矩阵的良态谱。
115
- - **`categorical`(抽象化)**:标准型即"等价类的代表元"——用最简形态抓住本质、忽略坐标细节。
116
- - **`probability-statistics`(概率与统计)**:随机化 NLA、随机矩阵谱、Perron–Frobenius/Markov 链平稳分布。
115
+ - **`categorical`(范畴化)**:标准型即"等价类的代表元"——用最简形态抓住本质、忽略坐标细节。
116
+ - **`probabilistic`(概率统计)**:随机化 NLA、随机矩阵谱、Perron–Frobenius/Markov 链平稳分布。
117
117
 
118
118
  ## 反模式
119
119
 
@@ -125,12 +125,12 @@
125
125
  - **数值上假设精确正定**:浮点下 Gram/协方差可能丢正定性,要加 jitter(对角抖动)或用 Cholesky 带 pivot。
126
126
  - **用 Frobenius 范数当低秩正则**:Frobenius / 权重衰减压的是"能量"不是"秩";要低秩得用核范数或显式低秩参数化(如 LoRA)。
127
127
  - **对非对称矩阵谈"特征值大小"**:度量能量/范数/稳定裕度该看**奇异值**;非正规矩阵的特征值模长会严重误导(瞬态增长远超谱半径预测)。
128
- - **把 O(n²) Gram 矩阵全量物化**:attention/核矩阵不分块就直接撑爆显存;应走 FlashAttention 式融合 + 分块(呼应 GPU 八维维度 4/8)。
128
+ - **把 O(n²) Gram 矩阵全量物化**:attention/核矩阵不分块就直接撑爆显存;应走 FlashAttention 式融合 + 分块(呼应 GPU 八维 D4/D8)。
129
129
  - **堆定理而不诊断瓶颈**:先问"算法瓶颈是谱、低秩还是稳定性",再选结构,别一上来灌矩阵理论。
130
130
 
131
131
  ## 深挖入口
132
132
 
133
- > **📖 书目信息**:Roger A. Horn & Charles R. Johnson, *Matrix Analysis*, 2nd Edition, Cambridge University Press, 2013. ISBN 978-0-521-83940-2.
133
+ > **书目信息**:Roger A. Horn & Charles R. Johnson, *Matrix Analysis*, 2nd Edition, Cambridge University Press, 2013. ISBN 978-0-521-83940-2.
134
134
  >
135
135
  > **启用方式**:将 `Matrix Analysis.pdf` 放入项目根目录的 `math_book/` 文件夹,Agent 即可自动搜索原文。PDF 不随 npm/git 分发(版权原因),需自行获取。
136
136