# 贝赖斯算法

**贝赖斯算法**（Bareiss algorithm）是高斯消元法在整环（一种非零乘积不可能为零的数系）上矩阵的无分数形式，例如在整数上，其中每一步消元都除以前一个主元，这个除法可证明是精确的，因此所有中间值都保留在原来的整环中，而不是进入分式域。它由埃尔温·H·贝赖斯（Erwin H. Bareiss）于1968年以《西尔维斯特恒等式与多步保整高斯消元法》为题发表在《计算数学》（*Mathematics of Computation*）上（第22卷，第103期，第565–578页），也被称为无分数高斯消元法或约当–贝赖斯方法<sup>[1](https://www.cecm.sfu.ca/CAG/code/Vol4No3/pp21-32.pdf)</sup>。

| 关键事实 | 详情 |
|---|---|
| 原始文献 | 埃尔温·H·贝赖斯，《计算数学》22(103): 565–578, 1968 |
| 目的 | 对线性方程组 \( AX = B \) 进行保整消元，使变换后系数的绝对值尽可能小 |
| 核心步骤 | 每个新元素除以前一个主元；根据西尔维斯特恒等式，该除法是精确的<sup>[2](https://link.springer.com/article/10.1007/s11786-020-00495-9)</sup> |
| 增长控制 | 朴素的无分数消元会使元素指数增长；贝赖斯将其降为线性增长<sup>[2](https://link.springer.com/article/10.1007/s11786-020-00495-9)</sup> |
| 中间量 | 每个中间元素都是原矩阵的一个子式，因此哈达玛不等式可以事先约束整个计算过程<sup>[3](https://www.numerical-linear-algebra.com/essays/a-bound-on-every-intermediate-at-once/)</sup> |
| 代价 | \( O(n^{3}) \) 次整环运算，与经典高斯消元法次数相同<sup>[4](https://charleshzh.github.io/oCAS/latest/en/math/linear-algebra.html)</sup> |
| 先例 | 道奇森和卡米尔·约当（Camille Jordan，1838–1922）更早已知晓；经贝赖斯的应用而广为人知<sup>[2](https://link.springer.com/article/10.1007/s11786-020-00495-9)</sup> |

## 所解决的问题

用普通高斯消元法在整数上精确求解线性方程组 \( AX = B \) 时，会迫使运算在有理数中进行：每一步元素都变成分数，其分子和分母不断增长，位数可能反复翻倍<sup>[5](https://www.kevos.com/engineering/linear-algebra-algorithms-over-fields)</sup>。另一种做法是通过交叉相乘消去分母，使运算保持在整数中进行，但元素的大小会指数增长<sup>[2](https://link.springer.com/article/10.1007/s11786-020-00495-9)</sup>。贝赖斯修改了高斯消元法，目的是在最后一步之前将所有计算保持在整环 \( \mathbb{D} \) 中，并利用西尔维斯特和约当的结果将元素增长从指数级降为线性级<sup>[2](https://link.springer.com/article/10.1007/s11786-020-00495-9)</sup>。

## 工作原理

贝赖斯将 \( A^{(k)}_{ij} \) 定义为由第 \( 1, \ldots, k, i \) 行和第 \( 1, \ldots, k, j \) 列构成的 \( (k+1) \times (k+1) \) 子矩阵的行列式，特殊情形为 \( A^{(0)}_{ij} = A_{ij} \) 和 \( A^{(-1)}_{0,0} = 1 \)<sup>[2](https://link.springer.com/article/10.1007/s11786-020-00495-9)</sup>。一步消元则为

\[ A^{(k+1)}_{i,j} = \frac{ A^{(k)}_{k+1,k+1} \, A^{(k)}_{i,j} - A^{(k)}_{i,k+1} \, A^{(k)}_{k+1,j} }{ A^{(k-1)}_{k,k} } \]

且该除法是精确的<sup>[2](https://link.springer.com/article/10.1007/s11786-020-00495-9)</sup>。在实现层面，令 \( p_0 = 1 \)，每个元素按 \( a^{(k+1)}_{ij} = ( a^{(k)}_{ij} \cdot a^{(k)}_{kk} - a^{(k)}_{ik} \cdot a^{(k)}_{kj} ) / p_k \) 更新，除数更新为 \( p_{k+1} = a^{(k)}_{kk} \)<sup>[4](https://charleshzh.github.io/oCAS/latest/en/math/linear-algebra.html)</sup>。

**为什么除法是精确的。** 贝赖斯定理（1968）指出，\( p_k \) 整除分子 \( a^{(k)}_{ij} \cdot a^{(k)}_{kk} - a^{(k)}_{ik} \cdot a^{(k)}_{kj} \)<sup>[4](https://charleshzh.github.io/oCAS/latest/en/math/linear-algebra.html)</sup>。解释在于西尔维斯特行列式恒等式：第 \( (k+1) \) 步的每次更新相当于计算一个 \( (k+2) \times (k+2) \) 子矩阵的行列式，而根据舒尔补公式，除以前一个主元后结果仍留在整环内<sup>[4](https://charleshzh.github.io/oCAS/latest/en/math/linear-algebra.html)</sup>。等价地说，简单的交叉相乘会在所有元素中引入一个系统性的公因子，而由于该因子已知，可以通过精确除法将其去除<sup>[2](https://link.springer.com/article/10.1007/s11786-020-00495-9)</sup>。

**中间量是什么。** 化简后矩阵的元素是 \( A \) 的子式<sup>[2](https://link.springer.com/article/10.1007/s11786-020-00495-9)</sup>。在第 \( k \) 步，尾随子矩阵的每个元素都是原矩阵的一个 \( (k+1) \times (k+1) \) 子式，是精确的而非近似的<sup>[3](https://www.numerical-linear-algebra.com/essays/a-bound-on-every-intermediate-at-once/)</sup>。这同时也给出一个界：哈达玛不等式适用于每个子式，因此一个不等式在计算开始之前就约束了整个计算过程，对于整数矩阵，中间值的位数增长到 \( O(n \log n) \)<sup>[3](https://www.numerical-linear-algebra.com/essays/a-bound-on-every-intermediate-at-once/)</sup><sup> • </sup><sup>[4](https://charleshzh.github.io/oCAS/latest/en/math/linear-algebra.html)</sup>。

## 两步法

贝赖斯在1968年论文中的主要兴趣是提倡一种“两步”方法，即从第 \( k \) 步直接进行到第 \( k+2 \) 步，而不是通过重复的高斯步骤。两步法声称效率更高，但所得结果相同<sup>[2](https://link.springer.com/article/10.1007/s11786-020-00495-9)</sup>。他1972年的后续论文《整环上矩阵问题的计算解法》（《数学及其应用学会杂志》第10卷，第68–104页）得出结论：两步消元法应被用于数值矩阵的求逆问题，特别是当尝试对矩阵求逆采用黑箱方法时，例如在商业分时系统中<sup>[6](https://academic.oup.com/imamat/article-abstract/10/1/68/724253)</sup>。

## 用途与扩展

**行列式与线性方程组。** 当必须精确计算整数矩阵的行列式时，贝赖斯算法执行无分数消元，其中每个中间量都等于某个子矩阵的行列式；这保证了所有除法都能整除，计算保持在整数中进行，最后一个主元给出行列式。<sup>[7](https://algorithms.alexli.ca/determinant-and-inverse/)</sup><sup> • </sup><sup>[8](https://kevos.com/pages/determinant-computation-strategies.html)</sup> 该方法适用于元素适中的中小型稠密整数矩阵，而对于更大的矩阵，更倾向于使用基于中国剩余定理重构的模方法<sup>[8](https://kevos.com/pages/determinant-computation-strategies.html)</sup>。美国国家标准与技术研究院的“计算处方”专栏描述了完全在整数模式下求整数矩阵行列式的贝赖斯方法，当需要精确答案时很有用，例如检验两个非常大的矩阵的行列式是否相等，对于非常大的元素还可以结合中国剩余定理<sup>[9](https://www.nist.gov/publications/determining-determinant)</sup>。

**无分数分解。** 贝赖斯算法产生LU分解的无分数变体，表示为 \( L D^{-1} U \) 分解，其中矩阵 \( P_r \)、\( L \)、\( D \)、\( U \) 和 \( P_c \) 只包含整环中的元素，而 \( D^{-1} \) 保持未求值状态，使所有计算都留在整环内<sup>[2](https://link.springer.com/article/10.1007/s11786-020-00495-9)</sup>。该算法会产生一行中所有元素的公因子，称为系统性因子，可以通过精确除法去除；其他公因子称为统计性因子，取决于具体的输入数据<sup>[2](https://link.springer.com/article/10.1007/s11786-020-00495-9)</sup>。无分数高斯–贝赖斯化简导致三角矩阵具有非平凡数量的行公因子<sup>[10](https://arxiv.org/abs/2005.12380)</sup>。

**软件。** SymPy的行列式例程对于大于 \( 3 \times 3 \) 的矩阵默认使用 `bareiss` 方法<sup>[11](https://fossies.org/linux/sympy/sympy/matrices/determinant.py)</sup>。Calcium库通过无分数LU分解提供 `bareiss` 行列式，需要 \( O(n^{3}) \) 次运算，并指出尽管是“无分数”的，当符号化简不完整时该算法仍可能引入分数<sup>[12](https://fredrikj.net/calcium/ca_mat.html)</sup>。oCAS计算机代数系统直接为其行列式和行阶梯形例程实现贝赖斯算法，其矩阵元素可以是整数、多项式、有限域元素或代数数域元素<sup>[4](https://charleshzh.github.io/oCAS/latest/en/math/linear-algebra.html)</sup>。

**应用。** 在参数化马尔可夫链的分析中，贝赖斯的一步无分数高斯消元法被用于符号化地计算可达概率；将每一步消元除以一个由构造已知的因子，可将解向量中所有多项式的次数限制在状态数以内<sup>[13](https://hci.iwr.uni-heidelberg.de/vislearn/HTML/people/lisa_kruse/publications/gandalf2017-extended.pdf)</sup>。对于对称正定托普利茨矩阵，贝赖斯分解算法已被证明是稳定的，数值实验将其行为与莱文森算法进行了比较<sup>[14](https://arxiv.org/abs/1004.5510)</sup>。

## 在精确方法中的地位

对于 \( \mathbb{Z} \) 和 \( \mathbb{Q} \) 上的精确线性代数，经典算法的无分数版本（如高斯消元法的贝赖斯版本）通常是 \( n \) 较小时的最佳方法，而多模或 \( p \)-进方法在 \( n \) 较大时更受青睐<sup>[15](https://www.researchgate.net/publication/346372929_On_a_fast_and_nearly_division-free_algorithm_for_the_characteristic_polynomial)</sup>。与执行 \( O(n^{4}) \) 次运算的无除法伯科维茨算法相比，贝赖斯路线需要 \( O(n^{3}) \) 次运算，但需要零测试，若零认证失败则可能失败<sup>[12](https://fredrikj.net/calcium/ca_mat.html)</sup>。后来的无分数算法在特殊情形下改进了贝赖斯：对于有理插值问题，一种算法至少比贝赖斯快一个数量级，而贝赖斯仍是那里所研究的通用有理插值问题中唯一已知可行的无分数方法<sup>[16](https://cs.uwaterloo.ca/~glabahn/Papers/exact.pdf)</sup>。

元素大小的界也说明了算法的代价。由于行列式的位长是矩阵本身固有的，任何精确计算它的过程都必须输出那么多位的整数；因此某个具体实例上27位这样的数字反映的是问题不可避免的代价，而不是无分数方法强加的额外开销。<sup>[3](https://www.numerical-linear-algebra.com/essays/a-bound-on-every-intermediate-at-once/)</sup>

## References

1. [The Berkowitz Algorithm, CECM](https://www.cecm.sfu.ca/CAG/code/Vol4No3/pp21-32.pdf)
2. [Common Factors in Fraction-Free Matrix Decompositions, Mathematics in Computer Science (Springer)](https://link.springer.com/article/10.1007/s11786-020-00495-9)
3. [A bound on every intermediate at once, Numerical Linear Algebra](https://www.numerical-linear-algebra.com/essays/a-bound-on-every-intermediate-at-once/)
4. [Foundations: Linear Algebra, oCAS documentation](https://charleshzh.github.io/oCAS/latest/en/math/linear-algebra.html)
5. [Linear Algebra Algorithms over Fields and Rings, KEVOS](https://www.kevos.com/engineering/linear-algebra-algorithms-over-fields)
6. [E. H. Bareiss (1972). Computational solutions of matrix problems over an integral domain. IMA Journal of Applied Mathematics 10(1), 68–104.](https://academic.oup.com/imamat/article-abstract/10/1/68/724253)
7. [Determinant and Inverse, Algorithms](https://algorithms.alexli.ca/determinant-and-inverse/)
8. [Determinant Computation Strategies, KEVOS](https://kevos.com/pages/determinant-computation-strategies.html)
9. [I. Beichl and F. Sullivan (2000). Determining the Determinant. Computing in Science and Engineering 2(5), NIST](https://www.nist.gov/publications/determining-determinant)
10. [Matrix factoring by fraction-free reduction (arXiv:2005.12380)](https://arxiv.org/abs/2005.12380)
11. [SymPy matrices/determinant.py source](https://fossies.org/linux/sympy/sympy/matrices/determinant.py)
12. [ca_mat.h, Calcium 0.4.0 documentation](https://fredrikj.net/calcium/ca_mat.html)
13. [Hutschenreiter, Baier, Klein. Parametric Markov Chains: PCTL Complexity and Fraction-free Gaussian Elimination](https://hci.iwr.uni-heidelberg.de/vislearn/HTML/people/lisa_kruse/publications/gandalf2017-extended.pdf)
14. [On the stability of the Bareiss and related Toeplitz factorization algorithms (arXiv:1004.5510)](https://arxiv.org/abs/1004.5510)
15. [On a fast and nearly division-free algorithm for the characteristic polynomial](https://www.researchgate.net/publication/346372929_On_a_fast_and_nearly_division-free_algorithm_for_the_characteristic_polynomial)
16. [Beckermann and Labahn. Fraction-free rational interpolants, SIAM J. Matrix Anal. Appl.](https://cs.uwaterloo.ca/~glabahn/Papers/exact.pdf)

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

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Computational and symbolic algebra › Symbolic and algebraic algorithms › Exact and symbolic linear algebra algorithms

Copyright 2026 Edgepedia

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

Source: https://www.edgepedia.org/zh/bareiss-algorithm

English original: https://www.edgepedia.org/bareiss-algorithm
