# 平方和

**平方和**是一种将平方量相加的表达式，这一短语命名了建立在上述运算之上的若干不同数学思想：数论中把整数表示为整数平方之和，统计学中用来度量变异性的平方偏差之和，以及优化中作为非负性证书的多项式平方和。平方量、目的与背景在每种情形下各不相同，但都利用了平方永不为负这一事实。

| 关键事实 | 详情 |
|---|---|
| 数论 | 拉格朗日四平方定理指出，每个自然数都可写成四个自然数的平方之和，\( n = x_1^2 + x_2^2 + x_3^2 + x_4^2 \)<sup>[1](https://mizar.uwb.edu.pl/version/current/html/lagra4sq.html)</sup><sup> • </sup><sup>[2](https://math.vanderbilt.edu/rolenl/SlidesLagrangeTheorem.pdf)</sup> |
| 推广 | 拉马努金找出了所有54个（在等价意义下）能表示每个正整数的二次型 \( ax_1^2 + bx_2^2 + cx_3^2 + dx_4^2 \)<sup>[3](https://arxiv.org/abs/1805.04353)</sup> |
| 统计学 | \( Ax \approx b \) 的最小二乘解使 \( b \) 与 \( Ax \) 各分量之差的平方和最小<sup>[4](https://www.textbooks.math.gatech.edu/ila/1553/least-squares.html)</sup> |
| 历史 | 勒让德于1805年发表最小二乘法；高斯称自1795年起便使用该原理，并于1809年发表了自己的论证<sup>[5](https://web.universiteitleiden.nl/fsw/verduin/stathist/sh_19.htm)</sup><sup> • </sup><sup>[6](https://link.springer.com/article/10.1007/s00407-022-00291-w)</sup> |
| 方差分析 | 在单因素方差分析中，总平方和分解为 \( SS(\text{Total}) = SST + SSE \)，即处理成分与误差成分<sup>[7](https://itl.nist.gov/div898/handbook/prc/section4/prc431.htm)</sup> |
| 回归 | 在回归中，总平方和分解为 \( SST = SSR + SSE \)，而 \( R^2 = SSR/SST \) 是模型所解释的总变异性比例<sup>[8](https://datascienceuwl.github.io/STAT145/textbook/chapters/anova-for-regression.html)</sup> |
| 优化 | 多项式的平方和分解可通过求解半定规划来计算<sup>[9](https://epubs.siam.org/doi/abs/10.1137/1.9781611972290.ch3)</sup> |

## 数论中的平方和

最古老的含义追问哪些整数可以写成平方和。拉格朗日四平方定理用四项回答了这个问题：对每个自然数 \( n \)，都存在自然数 \( x_1, x_2, x_3, x_4 \) 使得 \( n = x_1^2 + x_2^2 + x_3^2 + x_4^2 \)<sup>[1](https://mizar.uwb.edu.pl/version/current/html/lagra4sq.html)</sup><sup> • </sup><sup>[2](https://math.vanderbilt.edu/rolenl/SlidesLagrangeTheorem.pdf)</sup>。该定理已在证明助手中形式化；Mizar库正是通过存在四个满足此方程的自然数来定义“四平方和”，并从只需检验素数这一事实出发证明该定理<sup>[1](https://mizar.uwb.edu.pl/version/current/html/lagra4sq.html)</sup><sup> • </sup><sup>[10](https://isabelle.in.tum.de/website-Isabelle2019/dist/library/HOL/HOL-ex/Lagrange.html)</sup>。

这一结果已向两个方向推广。拉马努金推广了拉格朗日定理，给出了所有54个（在等价意义下）能表示所有正整数的二次型 \( ax_1^2 + bx_2^2 + cx_3^2 + dx_4^2 \)<sup>[3](https://arxiv.org/abs/1805.04353)</sup>。后来的工作研究表示 \( n = x^2 + y^2 + z^2 + w^2 \)，以及诸如 \( n = x^2 + y^2 + z^2 + 2w^2 \) 的变体，并带有涉及素数的线性限制<sup>[11](https://arxiv.org/abs/1811.08341)</sup>。

初等代数提供了实用的恒等式。对于两项，\( a^2 + b^2 = (a + b)^2 - 2ab \) 用和的平方改写平方和<sup>[12](https://www.geeksforgeeks.org/maths/sum-of-squares/)</sup>。

## 统计学中的平方和

在统计学中，平方和是平方偏差或平方残差之和，用来度量变异性。\( n \) 个测量值的方差为 \( s^2 = \sum_{i=1}^{n} (y_i - \bar{y})^2 / (n-1) \)；其分子称为均值偏差平方和，经过代数变形可改写为“原始平方和” \( \sum y_i^2 \) 减去“均值校正项” \( \frac{1}{n}(\sum y_i)^2 \)<sup>[7](https://itl.nist.gov/div898/handbook/prc/section4/prc431.htm)</sup>。

**最小二乘拟合。** 最小二乘法选择使残差平方和最小的参数。对于线性方程组 \( Ax \approx b \)，最小二乘解使 \( b \) 与 \( Ax \) 各分量之差的平方和最小，即两向量间的欧几里得距离的平方<sup>[4](https://www.textbooks.math.gatech.edu/ila/1553/least-squares.html)</sup>。在估计情形中，最小二乘方法寻找使残差平方和（记为SSE）最小的系数 \( \hat{\beta}_0 \) 与 \( \hat{\beta}_1 \)<sup>[13](https://www.sciencedirect.com/topics/mathematics/method-of-least-square)</sup>。

这一方法的历史是一场优先权之争。勒让德于1805年在其《确定彗星轨道的新方法》（*Nouvelles méthodes pour la détermination des orbites des comètes*）中发表了该方法，那是关于彗星轨道著作的一个附录<sup>[5](https://web.universiteitleiden.nl/fsw/verduin/stathist/sh_19.htm)</sup><sup> • </sup><sup>[14](https://www.gtfp.cs.rhul.ac.uk/pulskamp/Least_Squares/index.html)</sup>。高斯在其1809年关于天体运动的著作中称，他自1795年起便使用该原理，但勒让德率先发表<sup>[6](https://link.springer.com/article/10.1007/s00407-022-00291-w)</sup>。两人的论证性质不同：勒让德将该方法发展为一种不假设随机性的近似工具，而高斯则在随机变量与分布的背景下工作，证明了在误差服从正态分布时最大似然估计量等于最小二乘公式<sup>[6](https://link.springer.com/article/10.1007/s00407-022-00291-w)</sup>。高斯后来1823年的处理追问哪个线性无偏估计量方差最小，这一结果今称高斯–马尔可夫定理，它不依赖于正态性<sup>[6](https://link.springer.com/article/10.1007/s00407-022-00291-w)</sup>。

**方差分析与回归中的分解。** 方差分析围绕将总平方和拆分为归因于不同变异来源的成分而组织。在单因素方差分析中，指导原则是 \( SS(\text{Total}) = SST + SSE \)，其中 \( SST \)（处理平方和）度量各组均值围绕总均值的变异，\( SSE \)（误差平方和）度量组内变异<sup>[7](https://itl.nist.gov/div898/handbook/prc/section4/prc431.htm)</sup>。将每个平方和除以其自由度得到均方，\( MST = SST/(k-1) \) 与 \( MSE = SSE/(N-k) \)，其比值 \( F = MST/MSE \) 检验总体均值是否相等；当均值相等的原假设为真时，两个均方估计同一误差方差，其比值应接近1<sup>[15](https://www.itl.nist.gov/div898/handbook/prc/section4/prc423.htm)</sup>。

在回归中，同样的划分写作 \( SST = SSR + SSE \)，将响应变量的变异性拆分为模型解释的部分与未解释的部分；\( R^2 = SSR/SST \) 是解释比例，而 \( F \) 统计量 \( MSR/MSE \) 对模型整体进行检验<sup>[8](https://datascienceuwl.github.io/STAT145/textbook/chapters/anova-for-regression.html)</sup>。平方和也可分解为独立成分，例如将单因素方差分析的处理平方和分解为正交对比的平方和<sup>[16](https://www.stat.yale.edu/~jtc5/312_612/readings/Plane%20Answers%20to%20Complex%20Questions.pdf)</sup>。

## 多项式优化中的平方和

第三种含义涉及多项式。若一个实多项式可写成其他多项式的平方之和，则称其为平方和（SOS），这是该多项式处处非负的充分条件。该领域研究非负多项式、平方和与半定规划之间的关系，其两个核心思想是：多项式的平方和分解可用半定规划计算；在给定次数界的前提下，寻找实多项式系统不可行性证书是一个凸问题，可作为平方和规划求解<sup>[9](https://epubs.siam.org/doi/abs/10.1137/1.9781611972290.ch3)</sup>。

**计算代价。** 任何SOS规划都可转化为具有特定结构的半定规划（SDP），而这正是计算瓶颈：当多项式变量多、次数高时，生成的SDP规模大、求解代价高<sup>[17](https://arxiv.org/abs/1710.01358)</sup>。存在两类补救办法。利用稀疏性的方法利用系数匹配约束稀疏这一事实，非零元素密度为 \( \mathcal{O}(1/n^{2d}) \)，随变量数 \( n \) 或次数 \( 2d \) 增大而迅速下降；底层SDP中的弦稀疏性可产生具有更小半定约束的等价规划<sup>[17](https://arxiv.org/abs/1710.01358)</sup><sup> • </sup><sup>[18](https://www.sciencedirect.com/science/article/pii/S1367578821000717)</sup>。替代锥方法则完全用更易处理的凸规划取代半定规划：DSOS与SDSOS规划分别限制为对角占优与缩放对角占优结构，可用线性规划与二阶锥规划检验，而平方和基追踪等迭代方案可改进初始近似<sup>[17](https://arxiv.org/abs/1710.01358)</sup>。

近期一个统一框架通过“模式”这一概念——即决定哪些单项式被凸约束联系——来处理多项式优化的稀疏凸松弛，包括稠密半定松弛以及SONC、SAGE、TSSOS和SDSOS方法<sup>[19](https://ojmo.centre-mersenne.org/articles/10.5802/ojmo.50/)</sup>。可扩展性综述将平方和规划列为推动半定规划方法改进的应用之一，与机器学习、控制和机器人学并列<sup>[20](https://www.annualreviews.org/content/journals/10.1146/annurev-control-091819-074326)</sup>。

## References

1. [LAGRA4SQ: Lagrange's Four-Square Theorem, Yasushige Watase, Mizar Mathematical Library](https://mizar.uwb.edu.pl/version/current/html/lagra4sq.html)
2. [Number Theory Lecture, April 21: Lagrange's Four-Square Theorem, Vanderbilt University](https://math.vanderbilt.edu/rolenl/SlidesLagrangeTheorem.pdf)
3. [Extended Lagrange's four-square theorem, arXiv:1805.04353](https://arxiv.org/abs/1805.04353)
4. [The Method of Least Squares, Georgia Tech, Introduction to Linear Algebra](https://www.textbooks.math.gatech.edu/ila/1553/least-squares.html)
5. [A short history of probability and statistics: 19th century, Leiden University](https://web.universiteitleiden.nl/fsw/verduin/stathist/sh_19.htm)
6. [Magnus, J. R. (2022). Gauss on least-squares and maximum-likelihood estimation. Archive for History of Exact Sciences 76, 425–430](https://link.springer.com/article/10.1007/s00407-022-00291-w)
7. [7.4.3.1. One-way ANOVA overview, NIST/SEMATECH e-Handbook of Statistical Methods](https://itl.nist.gov/div898/handbook/prc/section4/prc431.htm)
8. [22. ANOVA for Regression, Introduction to Statistics: A Simulation-First Approach](https://datascienceuwl.github.io/STAT145/textbook/chapters/anova-for-regression.html)
9. [Parrilo, P. A. Polynomial Optimization, Sums of Squares, and Applications. In Semidefinite Optimization and Convex Algebraic Geometry, SIAM, ch. 3, pp. 47–157](https://epubs.siam.org/doi/abs/10.1137/1.9781611972290.ch3)
10. [Theory Lagrange, Isabelle/HOL-ex](https://isabelle.in.tum.de/website-Isabelle2019/dist/library/HOL/HOL-ex/Lagrange.html)
11. [Sums of squares with restrictions involving primes, arXiv:1811.08341](https://arxiv.org/abs/1811.08341)
12. [Sum of Squares, GeeksforGeeks](https://www.geeksforgeeks.org/maths/sum-of-squares/)
13. [Method of Least Square, ScienceDirect Topics](https://www.sciencedirect.com/topics/mathematics/method-of-least-square)
14. [Method of Least Squares, Royal Holloway, University of London](https://www.gtfp.cs.rhul.ac.uk/pulskamp/Least_Squares/index.html)
15. [7.4.2.3. The ANOVA table and tests of hypotheses about means, NIST/SEMATECH e-Handbook](https://www.itl.nist.gov/div898/handbook/prc/section4/prc423.htm)
16. [Breaking a Sum of Squares into Independent Components, Yale Statistics](https://www.stat.yale.edu/~jtc5/312_612/readings/Plane%20Answers%20to%20Complex%20Questions.pdf)
17. [Improving Efficiency and Scalability of Sum of Squares Optimization: Recent Advances and Limitations, arXiv:1710.01358](https://arxiv.org/abs/1710.01358)
18. [Chordal and factor-width decompositions for scalable semidefinite and polynomial optimization, ScienceDirect](https://www.sciencedirect.com/science/article/pii/S1367578821000717)
19. [Averkov, G., Peters, B., Sager, S. Unifying view on sparse convex relaxations in polynomial optimization. Open Journal of Optimization](https://ojmo.centre-mersenne.org/articles/10.5802/ojmo.50/)
20. [Recent Scalability Improvements for Semidefinite Programming with Applications in Machine Learning, Control, and Robotics, Annual Review of Control, Robotics, and Autonomous Systems](https://www.annualreviews.org/content/journals/10.1146/annurev-control-091819-074326)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Linear and multilinear algebra › Numerical linear algebra › Least squares and overdetermined systems

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/sum-of-squares

English original: https://www.edgepedia.org/sum-of-squares
