Topic

Factorizations and powers

LU

Elimination below the pivots, with each multiplier saved where it cleared an entry, writes PA = LU: L lower triangular with 1s on the diagonal, U the echelon form, P the row swaps. Solving with a new right side then costs only two triangular solves.

LDLᵀ

A symmetric matrix factors as L·D·Lᵀ with D diagonal. This is Cholesky without the square roots, so it stays exact, and the signs of D tell whether A is positive definite.

Powers by squaring

Aᵏ needs only about 2·log₂k multiplications: square A repeatedly and multiply together the powers that match the 1 bits of k. Negative powers use the inverse.

In code

import { lu, ldl, cholesky, power, algebraic } from "@ratmath/linalg";

const f = lu([[2, 1, 1], [4, 3, 3], [8, 7, 9]]).exact();
f.L.toStrings();   // [["1","0","0"], ["2","1","0"], ["4","3","1"]]
f.U.toStrings();   // [["2","1","1"], ["0","1","1"], ["0","0","2"]]
f.perm;            // [0, 1, 2]: no row swaps were needed

power([[1, 1], [1, 0]], 10).exact().toStrings();   // [["89","55"], ["55","34"]]
ldl([[4, 2], [2, 3]]).exact().positiveDefinite;    // true

// Cholesky with exact square roots
cholesky([[4, 2], [2, 3]]).exact().L.map((row) => row.map(algebraic.format));
// [["2", "0"], ["1", "√2"]]
Try itEdit the code and run it with @ratmath/linalg and Core's Rational, RationalInterval in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs