Nowadays, Julia includes an integer-determinant algorithm (the Bareiss algorithm), but only uses it by default for BigInt
matrices (since for fixed-width integer types like the default Int
a determinant will quickly overflow unless the matrix is tiny).
julia> using LinearAlgebra
julia> M = BigInt[10 20; 30 40]
2×2 Matrix{BigInt}:
10 20
30 40
julia> det(M) # exact BigInt determinant
-200
You can invoke the Bareiss algorithm explicitly for other integer types by calling LinearAlgebra.det_bareiss
, but beware that it can easily overflow for larger matrices:
julia> LinearAlgebra.det_bareiss([10 20; 30 40]) # exact Int determinant
-200
For example, with a 100 \times 100 matrix of random ±1 entries:
julia> A = rand([-1,1], 100,100);
julia> det(A) # floating-point approximation: fast and reasonably accurate
7.014043363270618e77
julia> det(BigInt.(A)) # exact
701404336326996708202480358186962679200983525458711992094310103304386652405760
julia> LinearAlgebra.det_bareiss(A) # overflows — bogus answer
746
PS. I just pushed a PR to clarify the det
documentation: document exact BigInt determinants by stevengj · Pull Request #53579 · JuliaLang/julia · GitHub