# Possible bug while calculating determinant?

Hello
I’m a high school junior and was recently self-studying linear algebra. I was reading about calculating determinants and the properties of them.
I read that whenever in a determinant, there are 2 similar rows (or columns), then the determinant value must be zero.

I have a habit of trying out all my math in julia too, so I wrote

``````julia> a = [1 2 3 7; 4 1 7 2; 5 7 1 9; 1 2 3 7]
4×4 Array{Int32,2}:
1  2  3  7
4  1  7  2
5  7  1  9
1  2  3  7

julia> det(a)
4.168280304250871e-14

``````

I’m surprised why didn’t it return zero but a very small number (maybe tending towards zero ?)

Thanks

``````julia> a
4×4 Array{Int64,2}:
1  2  3  7
4  1  7  2
5  7  1  9
1  2  3  7

julia> det(a)
0.0

julia> a = convert(Array{Int32}, a)
4×4 Array{Int32,2}:
1  2  3  7
4  1  7  2
5  7  1  9
1  2  3  7

julia> det(a)
0.0

julia> versioninfo()
Julia Version 1.3.1
Commit 2d5741174c (2019-12-30 21:36 UTC)
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
``````

What julia version are vou on?

Although (like @Sukera) I cannot replicate this using a recent Julia version, note that floating point arithmetic has some special properties you should be aware of.

If you are following along the calculations in a linear algebra text, you may want to convert to a type that is closed under the operations required for the determinant, eg

``````julia> det(Rational.(a))
0//1
``````

(Incidentally, I would recommend textbooks that place less emphasis on the determinant).

This is weird
Im on 1.0.4 the LTS version

I tried with numpy still didn’t get zero.

What does `julia> versioninfo()` say?
Do you get the same result if you first restart your computer?

Here it is

``````julia> versioninfo()
Julia Version 1.0.4
Commit 38e9fb7f80 (2019-05-16 03:38 UTC)
Platform Info:
OS: Linux (i686-pc-linux-gnu)
CPU: Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
WORD_SIZE: 32
LIBM: libopenlibm
LLVM: libLLVM-6.0.0 (ORCJIT, skylake)
``````

I find it a little surprising that Julia converts to floating point here given that the input array was full of `Int`s.

2 Likes

There’s no efficient way to compute exact integer determinants.

4 Likes