◂ the notebook

phycists.desmondbrown.me

Other projections⟨dev|Desmond⟩⟨ee|Desmond⟩⟨academic|Desmond⟩

No. 064 December 2025.
A CAD kernel in C++, and a working paper

Determinants two ways: cofactor expansion is O(n!), LU is O(n³)

My CAD kernel, written in C++, needed the determinant of a 4 × 4 matrix. Cofactor expansion was the obvious way: expand along the first row and recurse on the minors. Then I read how it scales. Each n × n determinant calls n determinants one size smaller, so the work grows as n!. Factoring A into L and U costs about n³, and the determinant is just the product of U’s diagonal.

det A = Σj (−1)1+j a1j det M1jandA = LU⇒det A = ∏ Uii

10⁰10³10⁶10⁹24681012cofactor expansion, grows as n!LU factorisation, about n³/3n = 4: 40 against 23matrix size n
10⁰10³10⁶10⁹24681012cofactor expansion, grows as n!LU factorisation, about n³/3n = 4: 40 against 23matrix size n
Multiplications and divisions, counted exactly for each method, on a log scale: cofactor expansion takes M(n) = n(M(n − 1) + 1); elimination without pivoting takes (n³ − n)/3, plus n − 1 for the diagonal product. Computed on this page.

The worked example from my notes, factored on this page:

A =2235910412L =1002.5102−0.751U =223042.500−2.125

det A = 2 × 4 × (−2.125) = −17

Cofactor expansion agrees: 2(18 − 10) − 2(10 − 40) + 3(5 − 36) = −17. The notes grew into a working paper, still in progress, with its abstract and introduction written; it is listed in the academic record.

what I don’t understand yet

When to pivot. My example never meets a small pivot, but in floating point a tiny one amplifies rounding error. Partial pivoting is in the paper’s plan, and I want to show the error growing numerically before I claim it.