Permutation matrices#

This module provides tools for computations of integrals of Haar random permutation matrices.

Permutation matrices Python interface

References

[1] Collins, B., & Nagatsu, M. (2025). Weingarten calculus for centered random permutation matrices. arXiv preprint arXiv:2503.18453.

haarpy.permutation.mobius_function(partition_1, partition_2)[source]#

Returns the Möbius function of two given partitions

Parameters:
  • partition_1 (tuple[tuple[int, ...], ...]) – The intersected partition

  • partition_2 (tuple[tuple[int, ...], ...]) – The partition summed over

Returns:

The value of the Möbius function

Return type:

int

Examples

>>> from haarpy import mobius_function
>>> partition_1 = ((0, 3), (1, 2), (4,), (5,))
>>> partition_2 = ((0, 1, 2), (3, 4, 5))
>>> mobius_function(partition_1, partition_2)
-2
haarpy.permutation.weingarten_permutation(first_partition, second_partition, dimension)[source]#

Returns the Weingarten function for random permutation matrices

Parameters:
  • first_partition (tuple[tuple[int, ...], ...]) – A partition of the set of \(k\) integers \([k] = \{1,2,\dots, k\}\)

  • second_partition (tuple[tuple[int, ...], ...]) – A second partition of the same set

  • dimension (Symbol) – The dimension of the random permutation matrices

Returns:

The Weingarten function

Return type:

Expr

Example

>>> from sympy import Symbol
>>> from haarpy import weingarten_permutation
>>> d = Symbol('d')
>>> partition_1 = ((0, 1, 2), (3,))
>>> partition_2 = ((0,), (1, 2, 3))
>>> weingarten_permutation(partition_1, partition_2, 4)
Fraction(5, 24)
>>> weingarten_permutation(partition_1, partition_2, d)
(d + 1)/(d*(d - 3)*(d - 2)*(d - 1))

See also

haarpy.partition.meet_operation()

Returns the greatest lower bound of the two input partitions

haarpy.permutation.mobius_function()

Returns the Möbius function of two given partitions

haarpy.permutation.weingarten_centered_permutation(first_partition, second_partition, dimension)[source]#

Returns the Weingarten function for centered random permutation matrices

Parameters:
  • first_partition (tuple[tuple[int, ...], ...]) – A partition of the set of \(k\) integers \([k] = \{1,2,\dots, k\}\)

  • second_partition (tuple[tuple[int, ...], ...]) – A second partition of the same set

  • dimension (Symbol) – The dimension of the random permutation matrices

Returns:

The Weingarten function

Return type:

Expr

Example

>>> from sympy import Symbol
>>> from haarpy import weingarten_centered_permutation
>>> d = Symbol('d')
>>> partition_1 = ((0,), (1,), (2,))
>>> partition_2 = ((0, 2), (1,))
>>> weingarten_centered_permutation(partition_1, partition_2, 3)
Fraction(-1, 9)
>>> weingarten_centered_permutation(partition_1, partition_2, d)
-2/(d**2*(d - 2)*(d - 1))

See also

haarpy.partition.meet_operation()

Returns the greatest lower bound of the two input partitions

haarpy.partition.join_operation()

Returns the least upper bound of the two input partitions

haarpy.permutation.mobius_function()

Returns the Möbius function of two given partitions

haarpy.permutation.haar_integral_permutation(row_indices, column_indices, dimension)[source]#

Returns the integral over Haar random permutation matrices

Parameters:
  • row_indices (tuple[int, ...]) – A sequence of row indices

  • column_indices (tuple[int, ...]) – A sequence of column indices

Returns:

The integral under the Haar measure

Return type:

Expr

Raises:
  • TypeError – If the input parameters are not of type Sequence

  • ValueError – If the input sequences are of different length

Examples

>>> from sympy import Symbol
>>> from haarpy import haar_integral_permutation
>>> d = Symbol('d')
>>> row_indices = (0, 1, 2, 2)
>>> column_indices = (1, 0, 2, 2)
>>> haar_integral_permutation(row_indices, column_indices, 3)
Fraction(1, 6)
>>> haar_integral_permutation(row_indices, column_indices, d)
1/(d*(d - 2)*(d - 1))

See also

haarpy.permutation.weingarten_permutation()

Returns the Weingarten function for random permutation matrices

haarpy.permutation.haar_integral_centered_permutation(row_indices, column_indices, dimension)[source]#

Returns the integral over Haar random centered permutation matrices

Parameters:
  • row_indices (tuple[int, ...]) – A sequence of row indices

  • column_indices (tuple[int, ...]) – A sequence of column indices

Returns:

The integral under the Haar measure

Return type:

Expr

Raises:
  • TypeError – If the input parameters are not of type Sequence

  • ValueError – If the input sequences are of different length

Examples

>>> from sympy import Symbol
>>> from haarpy import haar_integral_centered_permutation
>>> d = Symbol('d')
>>> row_indices = (0, 1, 2)
>>> column_indices = (0, 1, 1)
>>> haar_integral_centered_permutation(row_indices, column_indices, 3)
Fraction(-1, 27)
>>> haar_integral_centered_permutation(row_indices, column_indices, d)
-2/(d**3*(d - 1))

See also

haarpy.partition.partial_order()

Compares two partitions in terms of partial order

haarpy.permutation.weingarten_centered_permutation()

Returns the Weingarten function for centered random permutation matrices