Partition#

Description

Partition Python interface

References

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

[2] Matsumoto, S. (2013). Weingarten calculus for matrix ensembles associated with compact symmetric spaces. arXiv preprint arXiv:1301.5401.

[3] Nica, A., & Speicher, R. (2006). Lectures on the combinatorics of free probability (Vol. 13). Cambridge University Press.

haarpy.partition.set_partitions(collection)[source]#

Returns the partitionning of a given collection (set) of objects into non-empty subsets

Parameters:

collection (tuple) – An indexable iterable to be partitionned

Returns:

Iterator – All partitions of the input collection

Return type:

Iterator[tuple[tuple, ...]]

Raises:

ValueError – If the collection is not a tuple

Examples

>>> from haarpy import set_partitions
>>> for partition in set_partitions((0,1,2)):
>>>     print(partition)
((0, 1, 2),)
((0,), (1, 2))
((0, 1), (2,))
((0, 2), (1,))
((0,), (1,), (2,))
haarpy.partition.pair_partitions(seed)[source]#

Returns the pair partitions of a given set

Parameters:

seed (tuple[int, ...]) – A tuple representing the (multi-)set that will be partitioned. Note that it must hold that len(s) >= 2

Returns:

All the single-double partitions of the tuple

Return type:

Iterator[tuple[tuple[int, ...], ...]]

Raises:

TypeError – If the seed is not a tuple

Examples

>>> from haarpy import pair_partitions
>>> for matching in pair_partitions((0,1,2,3)):
>>>     print(matching)
((0, 1), (2, 3))
((0, 2), (1, 3))
((0, 3), (1, 2))
haarpy.partition.partial_order(partition_1, partition_2)[source]#

Checks if parition_1 <= partition_2 in terms of partial order

Parameters:
  • partition_1 (tuple[tuple[int, ...], ...]) – The partition of lower order

  • partition_2 (tuple[tuple[int, ...], ...]) – The partition of higher order

Returns:

True if partition_1 <= partition_2

Return type:

bool

Notes

For parition_1 and partition_2, two partitions of the same set, we call partition_1 <= partition_2 if and only if each block of partition_1 is contained in some block of partition_2

Examples

>>> from haarpy import partial_order
>>> partition_1 = ((0, 1), (2, 3), (4,))
>>> partition_2 = ((0, 1), (2, 3, 4))
>>> partition_3 = ((0, 4), (1, 2, 3))
>>> partial_order(partition_1, partition_2)
True
>>> partial_order(partition_1, partition_3)
False
haarpy.partition.meet_operation(partition_1, partition_2)[source]#

Returns the greatest lower bound of the two input partitions

Parameters:
  • partition_1 (tuple[tuple[int, ...], ...]) – The partition of a set

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

Returns:

The greatest lower bound

Return type:

tuple[tuple[int, ...], ...]

Notes

For parition_1 and partition_2, two partitions of the same set, the meet operation yields the greatest lower bound of both partitions

The meet operation symbol is , for instance ((0, 1), (2, 3), (4,)) ((0, 1, 2), (3, 4)) = ((0, 1), (2,), (3,), (4,))

Examples

>>> from haarpy import meet_operation
>>> partition_1 = ((0, 1), (2, 3), (4,))
>>> partition_2 = ((0, 1, 2), (3, 4))
>>> meet_operation(partition_1, partition_2)
((0, 1), (2,), (3,), (4,))
haarpy.partition.join_operation(partition_1, partition_2)[source]#

Returns the least upper bound of the two input partitions

Parameters:
  • partition_1 (tuple[tuple[int, ...], ...]) – The partition of a set

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

Returns:

The least upper bound

Return type:

tuple[tuple[int, ...], ...]

Notes

For parition_1 and partition_2, two partitions of the same set, the join operation yields the least upper bound of both partitions

The join operation symbol is , for instance ((0, 1), (2,), (3, 4)) ((0, 2), (1,), (3,), (4,)) = ((0, 1, 2), (3, 4))

Examples

>>> from haarpy import join_operation
>>> partition_1 = ((0, 1), (2,), (3, 4))
>>> partition_2 = ((0, 2), (1,), (3,), (4,))
>>> join_operation(partition_1, partition_2)
((0, 1, 2), (3, 4))
haarpy.partition.non_crossing_partitions(n, pair=False)[source]#

Yields non crossing partitions of the set \([n] = \{1,2,...,n\}\)

Parameters:
  • n (int) – The size of the partitioned set \([n]\)

  • pair (bool) – True to yield only pair partitions

Returns:

Yields the non-crossing partitions

Return type:

Iterator[tuple[tuple[int, ...], ...]]

Raises:
  • TypeError – If parameter n is not of type int

  • ValueError – If n < 0 or if pair is True and n is odd

Examples

>>> from haarpy import non_crossing_partitions
>>> for partition in non_crossing_partitions(3):
>>>     print(partition)
((0,), (1,), (2,))
((0,), (1, 2))
((0, 2), (1,))
((0, 1), (2,))
((0, 1, 2),)
>>> for partition in non_crossing_partitions(6, pair = True):
>>>     print(partition)
((0, 5), (1, 4), (2, 3))
((0, 5), (1, 2), (3, 4))
((0, 3), (1, 2), (4, 5))
((0, 1), (2, 5), (3, 4))
((0, 1), (2, 3), (4, 5))
haarpy.partition.is_crossing_partition(partition)[source]#

Checks if a given partition is crossing

Parameters:

partition (tuple[tuple[int, ...], ...]) – The partition of a set

Returns:

True if the partition is crossing, False otherwise

Return type:

bool

Examples

>>> from haarpy import is_crossing_partition
>>> is_crossing_partition(((0,2,4), (1,3)))
True
>>> is_crossing_partition(((0,3,4), (1,2)))
False
haarpy.partition.gram_matrix(partition_tuple, group_dimension)[source]#

Generates the Gram matrix of a given input set of partitions

Parameters:
  • partition_tuple (tuple[tuple[tuple[int, ...], ...], ...]) – A set of partitions

  • group_dimension (Symbol) – The dimension of the underlying group

Returns:

The symbolic Gram matrix

Return type:

MutableDenseMatrix

Raises:

TypeError – If the parameter group_dimension is neither a symbol or an integer

Examples

>>> from haarpy import gram_matrix
>>> from sympy import Symbol
>>> n = Symbol('n')
>>> pair_partition_tuple = (((0, 1), (2, 3)), ((0, 3), (1, 2)))
>>> gram_matrix(pair_partition_tuple, n)
Matrix([
[n**2,    n],
[   n, n**2]])