# Package to calculate permanent of a matrix?

**URL:** https://discourse.julialang.org/t/package-to-calculate-permanent-of-a-matrix/96844
**Category:** General Usage
**Tags:** question, package, math
**Created:** [March 30, 2023, 2:35pm UTC](https://discourse.julialang.org/t/package-to-calculate-permanent-of-a-matrix/96844 "2023-03-30T14:35:03Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![bmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmit/32/12443_2.png) [@bmit](https://discourse.julialang.org/u/bmit)
#### Post date: [March 30, 2023, 2:35pm UTC](https://discourse.julialang.org/t/package-to-calculate-permanent-of-a-matrix/96844/1 "2023-03-30T14:35:04Z")

</div>

I looked around and didn’t see any Julia tools for calculating the [permanent](https://en.wikipedia.org/wiki/Permanent_(mathematics)) of a matrix. Does anyone know of anything? I’m particularly interested in the [permanent of binary matrices](https://en.wikipedia.org/wiki/Permanent_(mathematics)#Permanents_of_(0,_1)_matrices) for counting applications.

I did find this discussion:

> [@Matrix permanent](https://discourse.julialang.org/t/matrix-permanent/10766):
>
> Any idea on how to improve the following code for computing the permanent of a matrix? I used the [Glynn formula](https://en.wikipedia.org/wiki/Computing_the_permanent#Balasubramanian%E2%80%93Bax%E2%80%93Franklin%E2%80%93Glynn_formula) where delta is obtained via Gray code. # from https://stackoverflow.com/questions/34236332/c-code-for-generating-next-bit-to-flip-in-a-gray-code function grayBitToFlip(n::Int) n1 = (n-1) ⊻ ((n-1)\>\>1) n2 = n ⊻ (n\>\>1) d = n1 ⊻ n2 j = 0 while d\>0 d \>\>= 1 j += 1 end j end function perm(A::AbstractMatrix{T}) where T n,m = size(A) if (n == m) D = Int8(1) δ = [Int8(2) …

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [March 30, 2023, 2:42pm UTC](https://discourse.julialang.org/t/package-to-calculate-permanent-of-a-matrix/96844/2 "2023-03-30T14:42:28Z")

</div>

Maybe

> **[GitHub - benoitseron/Permanents.jl: Functions to compute matrix permanents](https://github.com/benoitseron/Permanents.jl)**
>
> Functions to compute matrix permanents. Contribute to benoitseron/Permanents.jl development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![bmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmit/32/12443_2.png) [@bmit](https://discourse.julialang.org/u/bmit)
#### Post date: [March 30, 2023, 2:44pm UTC](https://discourse.julialang.org/t/package-to-calculate-permanent-of-a-matrix/96844/3 "2023-03-30T14:44:02Z")

</div>

🤦‍♂️

Note to self for next time: try `add Permanents`

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [March 30, 2023, 2:46pm UTC](https://discourse.julialang.org/t/package-to-calculate-permanent-of-a-matrix/96844/4 "2023-03-30T14:46:34Z")

</div>

I used the JuliaHub search functionality.

---

<div class="post-metadata">

### Author: ![bmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmit/32/12443_2.png) [@bmit](https://discourse.julialang.org/u/bmit)
#### Post date: [March 31, 2023, 12:42pm UTC](https://discourse.julialang.org/t/package-to-calculate-permanent-of-a-matrix/96844/5 "2023-03-31T12:42:09Z")

</div>

Very neat. I didn’t know that existed. Thanks again.
