Skip to content

Commit 8be21b7

Browse files
Merge pull request #2336 from fredrik-johansson/permanent
Followup #2335
2 parents 211e31a + 4c0965c commit 8be21b7

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

doc/source/history.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ History and changes
66
FLINT version history
77
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
88

9+
Future -- FLINT 3.4.0-dev
10+
-------------------------------------------------------------------------------
11+
12+
Main contributors: Fredrik Johansson (FJ)
13+
14+
* Features
15+
16+
* Matrix permanent (``gr_mat_permanent``) (FJ).
17+
18+
919
2025-06-11 -- FLINT 3.3.0
1020
-------------------------------------------------------------------------------
1121

src/python/flint_ctypes.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5647,6 +5647,38 @@ def det(self, algorithm=None):
56475647
if status & GR_DOMAIN: raise ValueError
56485648
return res
56495649

5650+
def permanent(self, algorithm=None):
5651+
"""
5652+
Permanent of this matrix.
5653+
5654+
>>> MatZZ(3, 3, ZZ.fac_vec(9)).permanent()
5655+
1995840
5656+
>>> Mat(RealField_arb(64))(8, 8, ZZ.fac_vec(64)).permanent()
5657+
[+/- 4.07e+321]
5658+
>>> Mat(RealField_arb(64))(8, 8, ZZ.fac_vec(64)).permanent(algorithm="cofactor")
5659+
[5.5848931822182876e+307 +/- 6.08e+290]
5660+
>>> Mat(RealField_arb(128))(8, 8, ZZ.fac_vec(64)).permanent()
5661+
[5.5849e+307 +/- 2.12e+302]
5662+
"""
5663+
element_ring = self.parent()._element_ring
5664+
res = element_ring()
5665+
if algorithm is None:
5666+
status = libgr.gr_mat_permanent(res._ref, self._ref, element_ring._ref)
5667+
elif algorithm == "cofactor":
5668+
status = libgr.gr_mat_permanent_cofactor(res._ref, self._ref, element_ring._ref)
5669+
elif algorithm == "ryser":
5670+
status = libgr.gr_mat_permanent_ryser(res._ref, self._ref, element_ring._ref)
5671+
elif algorithm == "glynn":
5672+
status = libgr.gr_mat_permanent_glynn(res._ref, self._ref, element_ring._ref)
5673+
elif algorithm == "glynn_threaded":
5674+
status = libgr.gr_mat_permanent_glynn_threaded(res._ref, self._ref, element_ring._ref)
5675+
else:
5676+
raise ValueError("unknown algorithm")
5677+
if status:
5678+
if status & GR_UNABLE: raise NotImplementedError
5679+
if status & GR_DOMAIN: raise ValueError
5680+
return res
5681+
56505682
def trace(self):
56515683
"""
56525684
>>> MatZZ([[3,4],[5,6]]).trace()

0 commit comments

Comments
 (0)