# Possible bug while calculating determinant?

**URL:** https://discourse.julialang.org/t/possible-bug-while-calculating-determinant/35960
**Category:** Specific Domains
**Tags:** linearalgebra
**Created:** [March 14, 2020, 8:54am UTC](https://discourse.julialang.org/t/possible-bug-while-calculating-determinant/35960 "2020-03-14T08:54:38Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![PseudoCodeNerd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pseudocodenerd/32/11948_2.png) [@PseudoCodeNerd](https://discourse.julialang.org/u/PseudoCodeNerd)
#### Post date: [March 14, 2020, 8:54am UTC](https://discourse.julialang.org/t/possible-bug-while-calculating-determinant/35960/1 "2020-03-14T08:54:38Z")

</div>

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
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

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [March 14, 2020, 9:08am UTC](https://discourse.julialang.org/t/possible-bug-while-calculating-determinant/35960/2 "2020-03-14T09:08:42Z")

</div>

```julia
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:
  JULIA_NUM_THREADS = 4

```

What julia version are vou on?

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [March 14, 2020, 9:15am UTC](https://discourse.julialang.org/t/possible-bug-while-calculating-determinant/35960/3 "2020-03-14T09:15:42Z")

</div>

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](https://discourse.julialang.org/t/psa-floating-point-arithmetic/8678).

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
julia> det(Rational.(a))
0//1

```

(Incidentally, I would recommend [textbooks that place less emphasis on the determinant](http://linear.axler.net/)).

---

<div class="post-metadata">

### Author: ![PseudoCodeNerd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pseudocodenerd/32/11948_2.png) [@PseudoCodeNerd](https://discourse.julialang.org/u/PseudoCodeNerd)
#### Post date: [March 14, 2020, 9:20am UTC](https://discourse.julialang.org/t/possible-bug-while-calculating-determinant/35960/4 "2020-03-14T09:20:37Z")

</div>

This is weird  
Im on 1.0.4 the LTS version

I tried with numpy still didn’t get zero.

---

<div class="post-metadata">

### Author: ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)
#### Post date: [March 14, 2020, 10:04am UTC](https://discourse.julialang.org/t/possible-bug-while-calculating-determinant/35960/5 "2020-03-14T10:04:38Z")

</div>

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

---

<div class="post-metadata">

### Author: ![PseudoCodeNerd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pseudocodenerd/32/11948_2.png) [@PseudoCodeNerd](https://discourse.julialang.org/u/PseudoCodeNerd)
#### Post date: [March 14, 2020, 10:59am UTC](https://discourse.julialang.org/t/possible-bug-while-calculating-determinant/35960/6 "2020-03-14T10:59:51Z")

</div>

Here it is

```julia
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)

```

---

<div class="post-metadata">

### Author: ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)
#### Post date: [March 14, 2020, 11:16am UTC](https://discourse.julialang.org/t/possible-bug-while-calculating-determinant/35960/7 "2020-03-14T11:16:39Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [March 14, 2020, 11:24am UTC](https://discourse.julialang.org/t/possible-bug-while-calculating-determinant/35960/8 "2020-03-14T11:24:05Z")

</div>

cf [Possible bug in determinant calculation - #8 by stevengj](https://discourse.julialang.org/t/possible-bug-in-determinant-calculation/20323/8).

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [March 14, 2020, 3:46pm UTC](https://discourse.julialang.org/t/possible-bug-while-calculating-determinant/35960/9 "2020-03-14T15:46:47Z")

</div>

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