Linear solve
64-bitx from A x = b for a small dense system.
Gaussian elimination with row exchange on the largest pivot, then back substitution
Partial pivoting on the absolute value in the column; the rows are not scaled first. Only a pivot below 1e-300 is called singular, so an ill-conditioned system is solved as it stands with no estimate of the digits lost.
/** Solve A x = b (A n×n row arrays) by Gaussian elimination with partial pivoting; returns null if singular. */
export function solveLinear(A, b) {
const n = b.length, M = A.map((r, i) => [...r, b[i]]);
for (let c = 0; c < n; c++) {
let p = c; for (let r = c + 1; r < n; r++) if (Math.abs(M[r][c]) > Math.abs(M[p][c])) p = r;
if (Math.abs(M[p][c]) < 1e-300) return null;
[M[c], M[p]] = [M[p], M[c]];
for (let r = c + 1; r < n; r++) { const f = M[r][c] / M[c][c]; if (f) for (let k = c; k <= n; k++) M[r][k] -= f * M[c][k]; }
}
const x = new Array(n);
for (let i = n - 1; i >= 0; i--) { let s = M[i][n]; for (let k = i + 1; k < n; k++) s -= M[i][k] * x[k]; x[i] = s / M[i][i]; }
return x;
}