Skip to content

permanent

qoptcraft.math.permanent

permanent(matrix, method='glynn')

Returns the permanent of a matrix using the Ryser formula in Gray ordering.

Parameters:

Name Type Description Default
matrix NDArray

A square matrix

required
method str

method to calculate the permanent. Options are 'glynn' and 'ryser'. Defaults to 'glynn'.

'glynn'

Returns:

Name Type Description
Number Number

the permanent of the matrix

Source code in qoptcraft/math/permanent.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def permanent(matrix: NDArray, method: Literal["glynn", "ryser"] = "glynn") -> Number:
    """Returns the permanent of a matrix using the Ryser formula in Gray ordering.

    Args:
        matrix (NDArray): A square matrix
        method (str): method to calculate the permanent. Options are 'glynn' and 'ryser'.
            Defaults to 'glynn'.

    Returns:
        Number: the permanent of the matrix
    """
    if method == "glynn":
        return _permanent_glynn(matrix)
    if method == "ryser":
        return _permanent_ryser(matrix)
    raise ValueError("Supported options for the permanent are 'glynn' and 'ryser'.")