Partition/diagram algebras

class sage.combinat.partition_algebra.PartitionAlgebraElement_ak[source]

Bases: PartitionAlgebraElement_generic

class sage.combinat.partition_algebra.PartitionAlgebraElement_bk[source]

Bases: PartitionAlgebraElement_generic

class sage.combinat.partition_algebra.PartitionAlgebraElement_generic[source]

Bases: IndexedFreeModuleElement

class sage.combinat.partition_algebra.PartitionAlgebraElement_pk[source]

Bases: PartitionAlgebraElement_generic

class sage.combinat.partition_algebra.PartitionAlgebraElement_prk[source]

Bases: PartitionAlgebraElement_generic

class sage.combinat.partition_algebra.PartitionAlgebraElement_rk[source]

Bases: PartitionAlgebraElement_generic

class sage.combinat.partition_algebra.PartitionAlgebraElement_sk[source]

Bases: PartitionAlgebraElement_generic

class sage.combinat.partition_algebra.PartitionAlgebraElement_tk[source]

Bases: PartitionAlgebraElement_generic

class sage.combinat.partition_algebra.PartitionAlgebra_ak(R, k, n, name=None)[source]

Bases: PartitionAlgebra_generic

EXAMPLES:

sage: from sage.combinat.partition_algebra import *
sage: p = PartitionAlgebra_ak(QQ, 3, 1)
sage: p == loads(dumps(p))
True
>>> from sage.all import *
>>> from sage.combinat.partition_algebra import *
>>> p = PartitionAlgebra_ak(QQ, Integer(3), Integer(1))
>>> p == loads(dumps(p))
True
from sage.combinat.partition_algebra import *
p = PartitionAlgebra_ak(QQ, 3, 1)
p == loads(dumps(p))
class sage.combinat.partition_algebra.PartitionAlgebra_bk(R, k, n, name=None)[source]

Bases: PartitionAlgebra_generic

EXAMPLES:

sage: from sage.combinat.partition_algebra import *
sage: p = PartitionAlgebra_bk(QQ, 3, 1)
sage: p == loads(dumps(p))
True
>>> from sage.all import *
>>> from sage.combinat.partition_algebra import *
>>> p = PartitionAlgebra_bk(QQ, Integer(3), Integer(1))
>>> p == loads(dumps(p))
True
from sage.combinat.partition_algebra import *
p = PartitionAlgebra_bk(QQ, 3, 1)
p == loads(dumps(p))
class sage.combinat.partition_algebra.PartitionAlgebra_generic(R, cclass, n, k, name=None, prefix=None)[source]

Bases: CombinatorialFreeModule

EXAMPLES:

sage: from sage.combinat.partition_algebra import *
sage: s = PartitionAlgebra_sk(QQ, 3, 1)
sage: TestSuite(s).run()                                                    # needs sage.graphs
sage: s == loads(dumps(s))
True
>>> from sage.all import *
>>> from sage.combinat.partition_algebra import *
>>> s = PartitionAlgebra_sk(QQ, Integer(3), Integer(1))
>>> TestSuite(s).run()                                                    # needs sage.graphs
>>> s == loads(dumps(s))
True
from sage.combinat.partition_algebra import *
s = PartitionAlgebra_sk(QQ, 3, 1)
TestSuite(s).run()                                                    # needs sage.graphs
s == loads(dumps(s))
one_basis()[source]

Return the basis index for the unit of the algebra.

EXAMPLES:

sage: from sage.combinat.partition_algebra import *
sage: s = PartitionAlgebra_sk(ZZ, 3, 1)
sage: len(s.one().support())   # indirect doctest
1
>>> from sage.all import *
>>> from sage.combinat.partition_algebra import *
>>> s = PartitionAlgebra_sk(ZZ, Integer(3), Integer(1))
>>> len(s.one().support())   # indirect doctest
1
from sage.combinat.partition_algebra import *
s = PartitionAlgebra_sk(ZZ, 3, 1)
len(s.one().support())   # indirect doctest
product_on_basis(left, right)[source]

EXAMPLES:

sage: from sage.combinat.partition_algebra import *
sage: s = PartitionAlgebra_sk(QQ, 3, 1)
sage: t12 = s(Set([Set([1,-2]),Set([2,-1]),Set([3,-3])]))
sage: t12^2 == s(1)  # indirect doctest                                     # needs sage.graphs
True
>>> from sage.all import *
>>> from sage.combinat.partition_algebra import *
>>> s = PartitionAlgebra_sk(QQ, Integer(3), Integer(1))
>>> t12 = s(Set([Set([Integer(1),-Integer(2)]),Set([Integer(2),-Integer(1)]),Set([Integer(3),-Integer(3)])]))
>>> t12**Integer(2) == s(Integer(1))  # indirect doctest                                     # needs sage.graphs
True
from sage.combinat.partition_algebra import *
s = PartitionAlgebra_sk(QQ, 3, 1)
t12 = s(Set([Set([1,-2]),Set([2,-1]),Set([3,-3])]))
t12^2 == s(1)  # indirect doctest                                     # needs sage.graphs
class sage.combinat.partition_algebra.PartitionAlgebra_pk(R, k, n, name=None)[source]

Bases: PartitionAlgebra_generic

EXAMPLES:

sage: from sage.combinat.partition_algebra import *
sage: p = PartitionAlgebra_pk(QQ, 3, 1)
sage: p == loads(dumps(p))
True
>>> from sage.all import *
>>> from sage.combinat.partition_algebra import *
>>> p = PartitionAlgebra_pk(QQ, Integer(3), Integer(1))
>>> p == loads(dumps(p))
True
from sage.combinat.partition_algebra import *
p = PartitionAlgebra_pk(QQ, 3, 1)
p == loads(dumps(p))
class sage.combinat.partition_algebra.PartitionAlgebra_prk(R, k, n, name=None)[source]

Bases: PartitionAlgebra_generic

EXAMPLES:

sage: from sage.combinat.partition_algebra import *
sage: p = PartitionAlgebra_prk(QQ, 3, 1)
sage: p == loads(dumps(p))
True
>>> from sage.all import *
>>> from sage.combinat.partition_algebra import *
>>> p = PartitionAlgebra_prk(QQ, Integer(3), Integer(1))
>>> p == loads(dumps(p))
True
from sage.combinat.partition_algebra import *
p = PartitionAlgebra_prk(QQ, 3, 1)
p == loads(dumps(p))
class sage.combinat.partition_algebra.PartitionAlgebra_rk(R, k, n, name=None)[source]

Bases: PartitionAlgebra_generic

EXAMPLES:

sage: from sage.combinat.partition_algebra import *
sage: p = PartitionAlgebra_rk(QQ, 3, 1)
sage: p == loads(dumps(p))
True
>>> from sage.all import *
>>> from sage.combinat.partition_algebra import *
>>> p = PartitionAlgebra_rk(QQ, Integer(3), Integer(1))
>>> p == loads(dumps(p))
True
from sage.combinat.partition_algebra import *
p = PartitionAlgebra_rk(QQ, 3, 1)
p == loads(dumps(p))
class sage.combinat.partition_algebra.PartitionAlgebra_sk(R, k, n, name=None)[source]

Bases: PartitionAlgebra_generic

EXAMPLES:

sage: from sage.combinat.partition_algebra import *
sage: p = PartitionAlgebra_sk(QQ, 3, 1)
sage: p == loads(dumps(p))
True
>>> from sage.all import *
>>> from sage.combinat.partition_algebra import *
>>> p = PartitionAlgebra_sk(QQ, Integer(3), Integer(1))
>>> p == loads(dumps(p))
True
from sage.combinat.partition_algebra import *
p = PartitionAlgebra_sk(QQ, 3, 1)
p == loads(dumps(p))
class sage.combinat.partition_algebra.PartitionAlgebra_tk(R, k, n, name=None)[source]

Bases: PartitionAlgebra_generic

EXAMPLES:

sage: from sage.combinat.partition_algebra import *
sage: p = PartitionAlgebra_tk(QQ, 3, 1)
sage: p == loads(dumps(p))
True
>>> from sage.all import *
>>> from sage.combinat.partition_algebra import *
>>> p = PartitionAlgebra_tk(QQ, Integer(3), Integer(1))
>>> p == loads(dumps(p))
True
from sage.combinat.partition_algebra import *
p = PartitionAlgebra_tk(QQ, 3, 1)
p == loads(dumps(p))
sage.combinat.partition_algebra.SetPartitionsAk(k)[source]

Return the combinatorial class of set partitions of type \(A_k\).

EXAMPLES:

sage: A3 = SetPartitionsAk(3); A3
Set partitions of {1, ..., 3, -1, ..., -3}

sage: A3.first() #random
{{1, 2, 3, -1, -3, -2}}
sage: A3.last() #random
{{-1}, {-2}, {3}, {1}, {-3}, {2}}
sage: A3.random_element()  #random                                              # needs sage.symbolic
{{1, 3, -3, -1}, {2, -2}}

sage: A3.cardinality()                                                          # needs sage.libs.flint
203

sage: A2p5 = SetPartitionsAk(2.5); A2p5
Set partitions of {1, ..., 3, -1, ..., -3} with 3 and -3 in the same block
sage: A2p5.cardinality()
52

sage: A2p5.first() #random
{{1, 2, 3, -1, -3, -2}}
sage: A2p5.last() #random
{{-1}, {-2}, {2}, {3, -3}, {1}}
sage: A2p5.random_element() #random                                             # needs sage.symbolic
{{-1}, {-2}, {3, -3}, {1, 2}}
>>> from sage.all import *
>>> A3 = SetPartitionsAk(Integer(3)); A3
Set partitions of {1, ..., 3, -1, ..., -3}

>>> A3.first() #random
{{1, 2, 3, -1, -3, -2}}
>>> A3.last() #random
{{-1}, {-2}, {3}, {1}, {-3}, {2}}
>>> A3.random_element()  #random                                              # needs sage.symbolic
{{1, 3, -3, -1}, {2, -2}}

>>> A3.cardinality()                                                          # needs sage.libs.flint
203

>>> A2p5 = SetPartitionsAk(RealNumber('2.5')); A2p5
Set partitions of {1, ..., 3, -1, ..., -3} with 3 and -3 in the same block
>>> A2p5.cardinality()
52

>>> A2p5.first() #random
{{1, 2, 3, -1, -3, -2}}
>>> A2p5.last() #random
{{-1}, {-2}, {2}, {3, -3}, {1}}
>>> A2p5.random_element() #random                                             # needs sage.symbolic
{{-1}, {-2}, {3, -3}, {1, 2}}
A3 = SetPartitionsAk(3); A3
A3.first() #random
A3.last() #random
A3.random_element()  #random                                              # needs sage.symbolic
A3.cardinality()                                                          # needs sage.libs.flint
A2p5 = SetPartitionsAk(2.5); A2p5
A2p5.cardinality()
A2p5.first() #random
A2p5.last() #random
A2p5.random_element() #random                                             # needs sage.symbolic
class sage.combinat.partition_algebra.SetPartitionsAk_k(k)[source]

Bases: SetPartitions_set

Element[source]

alias of SetPartitionsXkElement

class sage.combinat.partition_algebra.SetPartitionsAkhalf_k(k)[source]

Bases: SetPartitions_set

Element[source]

alias of SetPartitionsXkElement

sage.combinat.partition_algebra.SetPartitionsBk(k)[source]

Return the combinatorial class of set partitions of type \(B_k\).

These are the set partitions where every block has size 2.

EXAMPLES:

sage: B3 = SetPartitionsBk(3); B3
Set partitions of {1, ..., 3, -1, ..., -3} with block size 2

sage: # needs sage.graphs
sage: B3.first() #random
{{2, -2}, {1, -3}, {3, -1}}
sage: B3.last() #random
{{1, 2}, {3, -2}, {-3, -1}}
sage: B3.random_element() #random                                               # needs sage.symbolic
{{2, -1}, {1, -3}, {3, -2}}

sage: B3.cardinality()
15

sage: B2p5 = SetPartitionsBk(2.5); B2p5
Set partitions of {1, ..., 3, -1, ..., -3} with 3 and -3 in the same block and with block size 2

sage: # needs sage.graphs
sage: B2p5.first() #random
{{2, -1}, {3, -3}, {1, -2}}
sage: B2p5.last() #random
{{1, 2}, {3, -3}, {-1, -2}}
sage: B2p5.random_element() #random                                             # needs sage.symbolic
{{2, -2}, {3, -3}, {1, -1}}

sage: B2p5.cardinality()
3
>>> from sage.all import *
>>> B3 = SetPartitionsBk(Integer(3)); B3
Set partitions of {1, ..., 3, -1, ..., -3} with block size 2

>>> # needs sage.graphs
>>> B3.first() #random
{{2, -2}, {1, -3}, {3, -1}}
>>> B3.last() #random
{{1, 2}, {3, -2}, {-3, -1}}
>>> B3.random_element() #random                                               # needs sage.symbolic
{{2, -1}, {1, -3}, {3, -2}}

>>> B3.cardinality()
15

>>> B2p5 = SetPartitionsBk(RealNumber('2.5')); B2p5
Set partitions of {1, ..., 3, -1, ..., -3} with 3 and -3 in the same block and with block size 2

>>> # needs sage.graphs
>>> B2p5.first() #random
{{2, -1}, {3, -3}, {1, -2}}
>>> B2p5.last() #random
{{1, 2}, {3, -3}, {-1, -2}}
>>> B2p5.random_element() #random                                             # needs sage.symbolic
{{2, -2}, {3, -3}, {1, -1}}

>>> B2p5.cardinality()
3
B3 = SetPartitionsBk(3); B3
# needs sage.graphs
B3.first() #random
B3.last() #random
B3.random_element() #random                                               # needs sage.symbolic
B3.cardinality()
B2p5 = SetPartitionsBk(2.5); B2p5
# needs sage.graphs
B2p5.first() #random
B2p5.last() #random
B2p5.random_element() #random                                             # needs sage.symbolic
B2p5.cardinality()
class sage.combinat.partition_algebra.SetPartitionsBk_k(k)[source]

Bases: SetPartitionsAk_k

cardinality()[source]

Return the number of set partitions in \(B_k\) where \(k\) is an integer.

This is given by (2k)!! = (2k-1)*(2k-3)*…*5*3*1.

EXAMPLES:

sage: SetPartitionsBk(3).cardinality()
15
sage: SetPartitionsBk(2).cardinality()
3
sage: SetPartitionsBk(1).cardinality()
1
sage: SetPartitionsBk(4).cardinality()
105
sage: SetPartitionsBk(5).cardinality()
945
>>> from sage.all import *
>>> SetPartitionsBk(Integer(3)).cardinality()
15
>>> SetPartitionsBk(Integer(2)).cardinality()
3
>>> SetPartitionsBk(Integer(1)).cardinality()
1
>>> SetPartitionsBk(Integer(4)).cardinality()
105
>>> SetPartitionsBk(Integer(5)).cardinality()
945
SetPartitionsBk(3).cardinality()
SetPartitionsBk(2).cardinality()
SetPartitionsBk(1).cardinality()
SetPartitionsBk(4).cardinality()
SetPartitionsBk(5).cardinality()
class sage.combinat.partition_algebra.SetPartitionsBkhalf_k(k)[source]

Bases: SetPartitionsAkhalf_k

cardinality()[source]
sage.combinat.partition_algebra.SetPartitionsIk(k)[source]

Return the combinatorial class of set partitions of type \(I_k\).

These are set partitions with a propagating number of less than \(k\). Note that the identity set partition \(\{\{1, -1\}, \ldots, \{k, -k\}\}\) is not in \(I_k\).

EXAMPLES:

sage: I3 = SetPartitionsIk(3); I3
Set partitions of {1, ..., 3, -1, ..., -3} with propagating number < 3
sage: I3.cardinality()
197

sage: I3.first() #random
{{1, 2, 3, -1, -3, -2}}
sage: I3.last() #random
{{-1}, {-2}, {3}, {1}, {-3}, {2}}
sage: I3.random_element() #random                                               # needs sage.symbolic
{{-1}, {-3, -2}, {2, 3}, {1}}

sage: I2p5 = SetPartitionsIk(2.5); I2p5
Set partitions of {1, ..., 3, -1, ..., -3} with 3 and -3 in the same block and propagating number < 3
sage: I2p5.cardinality()
50

sage: I2p5.first() #random
{{1, 2, 3, -1, -3, -2}}
sage: I2p5.last() #random
{{-1}, {-2}, {2}, {3, -3}, {1}}
sage: I2p5.random_element() #random                                             # needs sage.symbolic
{{-1}, {-2}, {1, 3, -3}, {2}}
>>> from sage.all import *
>>> I3 = SetPartitionsIk(Integer(3)); I3
Set partitions of {1, ..., 3, -1, ..., -3} with propagating number < 3
>>> I3.cardinality()
197

>>> I3.first() #random
{{1, 2, 3, -1, -3, -2}}
>>> I3.last() #random
{{-1}, {-2}, {3}, {1}, {-3}, {2}}
>>> I3.random_element() #random                                               # needs sage.symbolic
{{-1}, {-3, -2}, {2, 3}, {1}}

>>> I2p5 = SetPartitionsIk(RealNumber('2.5')); I2p5
Set partitions of {1, ..., 3, -1, ..., -3} with 3 and -3 in the same block and propagating number < 3
>>> I2p5.cardinality()
50

>>> I2p5.first() #random
{{1, 2, 3, -1, -3, -2}}
>>> I2p5.last() #random
{{-1}, {-2}, {2}, {3, -3}, {1}}
>>> I2p5.random_element() #random                                             # needs sage.symbolic
{{-1}, {-2}, {1, 3, -3}, {2}}
I3 = SetPartitionsIk(3); I3
I3.cardinality()
I3.first() #random
I3.last() #random
I3.random_element() #random                                               # needs sage.symbolic
I2p5 = SetPartitionsIk(2.5); I2p5
I2p5.cardinality()
I2p5.first() #random
I2p5.last() #random
I2p5.random_element() #random                                             # needs sage.symbolic
class sage.combinat.partition_algebra.SetPartitionsIk_k(k)[source]

Bases: SetPartitionsAk_k

cardinality()[source]
class sage.combinat.partition_algebra.SetPartitionsIkhalf_k(k)[source]

Bases: SetPartitionsAkhalf_k

cardinality()[source]
sage.combinat.partition_algebra.SetPartitionsPRk(k)[source]

Return the combinatorial class of set partitions of type \(PR_k\).

EXAMPLES:

sage: SetPartitionsPRk(3)
Set partitions of {1, ..., 3, -1, ..., -3} with at most 1 positive
 and negative entry in each block and that are planar
>>> from sage.all import *
>>> SetPartitionsPRk(Integer(3))
Set partitions of {1, ..., 3, -1, ..., -3} with at most 1 positive
 and negative entry in each block and that are planar
SetPartitionsPRk(3)
class sage.combinat.partition_algebra.SetPartitionsPRk_k(k)[source]

Bases: SetPartitionsRk_k

cardinality()[source]
class sage.combinat.partition_algebra.SetPartitionsPRkhalf_k(k)[source]

Bases: SetPartitionsRkhalf_k

cardinality()[source]
sage.combinat.partition_algebra.SetPartitionsPk(k)[source]

Return the combinatorial class of set partitions of type \(P_k\).

These are the planar set partitions.

EXAMPLES:

sage: P3 = SetPartitionsPk(3); P3
Set partitions of {1, ..., 3, -1, ..., -3} that are planar
sage: P3.cardinality()
132

sage: P3.first() #random
{{1, 2, 3, -1, -3, -2}}
sage: P3.last() #random
{{-1}, {-2}, {3}, {1}, {-3}, {2}}
sage: P3.random_element() #random                                               # needs sage.symbolic
{{1, 2, -1}, {-3}, {3, -2}}

sage: P2p5 = SetPartitionsPk(2.5); P2p5
Set partitions of {1, ..., 3, -1, ..., -3} with 3 and -3 in the same block and that are planar
sage: P2p5.cardinality()
42

sage: P2p5.first() #random
{{1, 2, 3, -1, -3, -2}}
sage: P2p5.last() #random
{{-1}, {-2}, {2}, {3, -3}, {1}}
sage: P2p5.random_element() #random                                             # needs sage.symbolic
{{1, 2, 3, -3}, {-1, -2}}
>>> from sage.all import *
>>> P3 = SetPartitionsPk(Integer(3)); P3
Set partitions of {1, ..., 3, -1, ..., -3} that are planar
>>> P3.cardinality()
132

>>> P3.first() #random
{{1, 2, 3, -1, -3, -2}}
>>> P3.last() #random
{{-1}, {-2}, {3}, {1}, {-3}, {2}}
>>> P3.random_element() #random                                               # needs sage.symbolic
{{1, 2, -1}, {-3}, {3, -2}}

>>> P2p5 = SetPartitionsPk(RealNumber('2.5')); P2p5
Set partitions of {1, ..., 3, -1, ..., -3} with 3 and -3 in the same block and that are planar
>>> P2p5.cardinality()
42

>>> P2p5.first() #random
{{1, 2, 3, -1, -3, -2}}
>>> P2p5.last() #random
{{-1}, {-2}, {2}, {3, -3}, {1}}
>>> P2p5.random_element() #random                                             # needs sage.symbolic
{{1, 2, 3, -3}, {-1, -2}}
P3 = SetPartitionsPk(3); P3
P3.cardinality()
P3.first() #random
P3.last() #random
P3.random_element() #random                                               # needs sage.symbolic
P2p5 = SetPartitionsPk(2.5); P2p5
P2p5.cardinality()
P2p5.first() #random
P2p5.last() #random
P2p5.random_element() #random                                             # needs sage.symbolic
class sage.combinat.partition_algebra.SetPartitionsPk_k(k)[source]

Bases: SetPartitionsAk_k

cardinality()[source]
class sage.combinat.partition_algebra.SetPartitionsPkhalf_k(k)[source]

Bases: SetPartitionsAkhalf_k

cardinality()[source]
sage.combinat.partition_algebra.SetPartitionsRk(k)[source]

Return the combinatorial class of set partitions of type \(R_k\).

EXAMPLES:

sage: SetPartitionsRk(3)
Set partitions of {1, ..., 3, -1, ..., -3} with at most 1 positive
 and negative entry in each block
>>> from sage.all import *
>>> SetPartitionsRk(Integer(3))
Set partitions of {1, ..., 3, -1, ..., -3} with at most 1 positive
 and negative entry in each block
SetPartitionsRk(3)
class sage.combinat.partition_algebra.SetPartitionsRk_k(k)[source]

Bases: SetPartitionsAk_k

cardinality()[source]
class sage.combinat.partition_algebra.SetPartitionsRkhalf_k(k)[source]

Bases: SetPartitionsAkhalf_k

cardinality()[source]
sage.combinat.partition_algebra.SetPartitionsSk(k)[source]

Return the combinatorial class of set partitions of type \(S_k\).

There is a bijection between these set partitions and the permutations of \(1, \ldots, k\).

EXAMPLES:

sage: S3 = SetPartitionsSk(3); S3
Set partitions of {1, ..., 3, -1, ..., -3} with propagating number 3
sage: S3.cardinality()
6

sage: S3.list()  #random
[{{2, -2}, {3, -3}, {1, -1}},
 {{1, -1}, {2, -3}, {3, -2}},
 {{2, -1}, {3, -3}, {1, -2}},
 {{1, -2}, {2, -3}, {3, -1}},
 {{1, -3}, {2, -1}, {3, -2}},
 {{1, -3}, {2, -2}, {3, -1}}]
sage: S3.first() #random
{{2, -2}, {3, -3}, {1, -1}}
sage: S3.last() #random
{{1, -3}, {2, -2}, {3, -1}}
sage: S3.random_element() #random                                               # needs sage.symbolic
{{1, -3}, {2, -1}, {3, -2}}

sage: S3p5 = SetPartitionsSk(3.5); S3p5
Set partitions of {1, ..., 4, -1, ..., -4} with 4 and -4 in the same block and propagating number 4
sage: S3p5.cardinality()
6

sage: S3p5.list() #random
[{{2, -2}, {3, -3}, {1, -1}, {4, -4}},
 {{2, -3}, {1, -1}, {4, -4}, {3, -2}},
 {{2, -1}, {3, -3}, {1, -2}, {4, -4}},
 {{2, -3}, {1, -2}, {4, -4}, {3, -1}},
 {{1, -3}, {2, -1}, {4, -4}, {3, -2}},
 {{1, -3}, {2, -2}, {4, -4}, {3, -1}}]
sage: S3p5.first() #random
{{2, -2}, {3, -3}, {1, -1}, {4, -4}}
sage: S3p5.last() #random
{{1, -3}, {2, -2}, {4, -4}, {3, -1}}
sage: S3p5.random_element() #random                                             # needs sage.symbolic
{{1, -3}, {2, -2}, {4, -4}, {3, -1}}
>>> from sage.all import *
>>> S3 = SetPartitionsSk(Integer(3)); S3
Set partitions of {1, ..., 3, -1, ..., -3} with propagating number 3
>>> S3.cardinality()
6

>>> S3.list()  #random
[{{2, -2}, {3, -3}, {1, -1}},
 {{1, -1}, {2, -3}, {3, -2}},
 {{2, -1}, {3, -3}, {1, -2}},
 {{1, -2}, {2, -3}, {3, -1}},
 {{1, -3}, {2, -1}, {3, -2}},
 {{1, -3}, {2, -2}, {3, -1}}]
>>> S3.first() #random
{{2, -2}, {3, -3}, {1, -1}}
>>> S3.last() #random
{{1, -3}, {2, -2}, {3, -1}}
>>> S3.random_element() #random                                               # needs sage.symbolic
{{1, -3}, {2, -1}, {3, -2}}

>>> S3p5 = SetPartitionsSk(RealNumber('3.5')); S3p5
Set partitions of {1, ..., 4, -1, ..., -4} with 4 and -4 in the same block and propagating number 4
>>> S3p5.cardinality()
6

>>> S3p5.list() #random
[{{2, -2}, {3, -3}, {1, -1}, {4, -4}},
 {{2, -3}, {1, -1}, {4, -4}, {3, -2}},
 {{2, -1}, {3, -3}, {1, -2}, {4, -4}},
 {{2, -3}, {1, -2}, {4, -4}, {3, -1}},
 {{1, -3}, {2, -1}, {4, -4}, {3, -2}},
 {{1, -3}, {2, -2}, {4, -4}, {3, -1}}]
>>> S3p5.first() #random
{{2, -2}, {3, -3}, {1, -1}, {4, -4}}
>>> S3p5.last() #random
{{1, -3}, {2, -2}, {4, -4}, {3, -1}}
>>> S3p5.random_element() #random                                             # needs sage.symbolic
{{1, -3}, {2, -2}, {4, -4}, {3, -1}}
S3 = SetPartitionsSk(3); S3
S3.cardinality()
S3.list()  #random
S3.first() #random
S3.last() #random
S3.random_element() #random                                               # needs sage.symbolic
S3p5 = SetPartitionsSk(3.5); S3p5
S3p5.cardinality()
S3p5.list() #random
S3p5.first() #random
S3p5.last() #random
S3p5.random_element() #random                                             # needs sage.symbolic
class sage.combinat.partition_algebra.SetPartitionsSk_k(k)[source]

Bases: SetPartitionsAk_k

cardinality()[source]

Return k!.

class sage.combinat.partition_algebra.SetPartitionsSkhalf_k(k)[source]

Bases: SetPartitionsAkhalf_k

cardinality()[source]
sage.combinat.partition_algebra.SetPartitionsTk(k)[source]

Return the combinatorial class of set partitions of type \(T_k\).

These are planar set partitions where every block is of size 2.

EXAMPLES:

sage: T3 = SetPartitionsTk(3); T3
Set partitions of {1, ..., 3, -1, ..., -3} with block size 2 and that are planar
sage: T3.cardinality()
5

sage: # needs sage.graphs
sage: T3.first()             # random
{{1, -3}, {2, 3}, {-1, -2}}
sage: T3.last()              # random
{{1, 2}, {3, -1}, {-3, -2}}
sage: T3.random_element()    # random                                           # needs sage.symbolic
{{1, -3}, {2, 3}, {-1, -2}}

sage: T2p5 = SetPartitionsTk(2.5); T2p5
Set partitions of {1, ..., 3, -1, ..., -3} with 3 and -3 in the same block and with block size 2 and that are planar
sage: T2p5.cardinality()
2

sage: # needs sage.graphs
sage: T2p5.first()           # random
{{2, -2}, {3, -3}, {1, -1}}
sage: T2p5.last()            # random
{{1, 2}, {3, -3}, {-1, -2}}
>>> from sage.all import *
>>> T3 = SetPartitionsTk(Integer(3)); T3
Set partitions of {1, ..., 3, -1, ..., -3} with block size 2 and that are planar
>>> T3.cardinality()
5

>>> # needs sage.graphs
>>> T3.first()             # random
{{1, -3}, {2, 3}, {-1, -2}}
>>> T3.last()              # random
{{1, 2}, {3, -1}, {-3, -2}}
>>> T3.random_element()    # random                                           # needs sage.symbolic
{{1, -3}, {2, 3}, {-1, -2}}

>>> T2p5 = SetPartitionsTk(RealNumber('2.5')); T2p5
Set partitions of {1, ..., 3, -1, ..., -3} with 3 and -3 in the same block and with block size 2 and that are planar
>>> T2p5.cardinality()
2

>>> # needs sage.graphs
>>> T2p5.first()           # random
{{2, -2}, {3, -3}, {1, -1}}
>>> T2p5.last()            # random
{{1, 2}, {3, -3}, {-1, -2}}
T3 = SetPartitionsTk(3); T3
T3.cardinality()
# needs sage.graphs
T3.first()             # random
T3.last()              # random
T3.random_element()    # random                                           # needs sage.symbolic
T2p5 = SetPartitionsTk(2.5); T2p5
T2p5.cardinality()
# needs sage.graphs
T2p5.first()           # random
T2p5.last()            # random
class sage.combinat.partition_algebra.SetPartitionsTk_k(k)[source]

Bases: SetPartitionsBk_k

cardinality()[source]
class sage.combinat.partition_algebra.SetPartitionsTkhalf_k(k)[source]

Bases: SetPartitionsBkhalf_k

cardinality()[source]
class sage.combinat.partition_algebra.SetPartitionsXkElement(parent, s, check=True)[source]

Bases: SetPartition

An element for the classes of SetPartitionXk where X is some letter.

check()[source]

Check to make sure this is a set partition.

EXAMPLES:

sage: A2p5 = SetPartitionsAk(2.5)
sage: x = A2p5.first(); x
{{-3, -2, -1, 1, 2, 3}}
sage: x.check()
sage: y = A2p5.next(x); y
{{-3, 3}, {-2, -1, 1, 2}}
sage: y.check()
>>> from sage.all import *
>>> A2p5 = SetPartitionsAk(RealNumber('2.5'))
>>> x = A2p5.first(); x
{{-3, -2, -1, 1, 2, 3}}
>>> x.check()
>>> y = A2p5.next(x); y
{{-3, 3}, {-2, -1, 1, 2}}
>>> y.check()
A2p5 = SetPartitionsAk(2.5)
x = A2p5.first(); x
x.check()
y = A2p5.next(x); y
y.check()
sage.combinat.partition_algebra.identity(k)[source]

Return the identity set partition \(1, -1, \ldots, k, -k\).

EXAMPLES:

sage: import sage.combinat.partition_algebra as pa
sage: pa.identity(2)
{{2, -2}, {1, -1}}
>>> from sage.all import *
>>> import sage.combinat.partition_algebra as pa
>>> pa.identity(Integer(2))
{{2, -2}, {1, -1}}
import sage.combinat.partition_algebra as pa
pa.identity(2)
sage.combinat.partition_algebra.is_planar(sp)[source]

Return True if the diagram corresponding to the set partition is planar; otherwise, it returns False.

EXAMPLES:

sage: import sage.combinat.partition_algebra as pa
sage: pa.is_planar( pa.to_set_partition([[1,-2],[2,-1]]))
False
sage: pa.is_planar( pa.to_set_partition([[1,-1],[2,-2]]))
True
>>> from sage.all import *
>>> import sage.combinat.partition_algebra as pa
>>> pa.is_planar( pa.to_set_partition([[Integer(1),-Integer(2)],[Integer(2),-Integer(1)]]))
False
>>> pa.is_planar( pa.to_set_partition([[Integer(1),-Integer(1)],[Integer(2),-Integer(2)]]))
True
import sage.combinat.partition_algebra as pa
pa.is_planar( pa.to_set_partition([[1,-2],[2,-1]]))
pa.is_planar( pa.to_set_partition([[1,-1],[2,-2]]))
sage.combinat.partition_algebra.pair_to_graph(sp1, sp2)[source]

Return a graph consisting of the disjoint union of the graphs of set partitions sp1 and sp2 along with edges joining the bottom row (negative numbers) of sp1 to the top row (positive numbers) of sp2.

The vertices of the graph sp1 appear in the result as pairs (k, 1), whereas the vertices of the graph sp2 appear as pairs (k, 2).

EXAMPLES:

sage: # needs sage.graphs
sage: import sage.combinat.partition_algebra as pa
sage: sp1 = pa.to_set_partition([[1,-2],[2,-1]])
sage: sp2 = pa.to_set_partition([[1,-2],[2,-1]])
sage: g = pa.pair_to_graph( sp1, sp2 ); g
Graph on 8 vertices
>>> from sage.all import *
>>> # needs sage.graphs
>>> import sage.combinat.partition_algebra as pa
>>> sp1 = pa.to_set_partition([[Integer(1),-Integer(2)],[Integer(2),-Integer(1)]])
>>> sp2 = pa.to_set_partition([[Integer(1),-Integer(2)],[Integer(2),-Integer(1)]])
>>> g = pa.pair_to_graph( sp1, sp2 ); g
Graph on 8 vertices
# needs sage.graphs
import sage.combinat.partition_algebra as pa
sp1 = pa.to_set_partition([[1,-2],[2,-1]])
sp2 = pa.to_set_partition([[1,-2],[2,-1]])
g = pa.pair_to_graph( sp1, sp2 ); g

sage: # needs sage.graphs
sage: g.vertices(sort=False) #random
[(1, 2), (-1, 1), (-2, 2), (-1, 2), (-2, 1), (2, 1), (2, 2), (1, 1)]
sage: g.edges(sort=False) #random
[((1, 2), (-1, 1), None),
 ((1, 2), (-2, 2), None),
 ((-1, 1), (2, 1), None),
 ((-1, 2), (2, 2), None),
 ((-2, 1), (1, 1), None),
 ((-2, 1), (2, 2), None)]
>>> from sage.all import *
>>> # needs sage.graphs
>>> g.vertices(sort=False) #random
[(1, 2), (-1, 1), (-2, 2), (-1, 2), (-2, 1), (2, 1), (2, 2), (1, 1)]
>>> g.edges(sort=False) #random
[((1, 2), (-1, 1), None),
 ((1, 2), (-2, 2), None),
 ((-1, 1), (2, 1), None),
 ((-1, 2), (2, 2), None),
 ((-2, 1), (1, 1), None),
 ((-2, 1), (2, 2), None)]
# needs sage.graphs
g.vertices(sort=False) #random
g.edges(sort=False) #random

Another example which used to be wrong until upstream Issue #15958:

sage: # needs sage.graphs
sage: sp3 = pa.to_set_partition([[1, -1], [2], [-2]])
sage: sp4 = pa.to_set_partition([[1], [-1], [2], [-2]])
sage: g = pa.pair_to_graph( sp3, sp4 ); g
Graph on 8 vertices
sage: g.vertices(sort=True)
[(-2, 1), (-2, 2), (-1, 1), (-1, 2), (1, 1), (1, 2), (2, 1), (2, 2)]
sage: g.edges(sort=True)
[((-2, 1), (2, 2), None), ((-1, 1), (1, 1), None),
 ((-1, 1), (1, 2), None)]
>>> from sage.all import *
>>> # needs sage.graphs
>>> sp3 = pa.to_set_partition([[Integer(1), -Integer(1)], [Integer(2)], [-Integer(2)]])
>>> sp4 = pa.to_set_partition([[Integer(1)], [-Integer(1)], [Integer(2)], [-Integer(2)]])
>>> g = pa.pair_to_graph( sp3, sp4 ); g
Graph on 8 vertices
>>> g.vertices(sort=True)
[(-2, 1), (-2, 2), (-1, 1), (-1, 2), (1, 1), (1, 2), (2, 1), (2, 2)]
>>> g.edges(sort=True)
[((-2, 1), (2, 2), None), ((-1, 1), (1, 1), None),
 ((-1, 1), (1, 2), None)]
# needs sage.graphs
sp3 = pa.to_set_partition([[1, -1], [2], [-2]])
sp4 = pa.to_set_partition([[1], [-1], [2], [-2]])
g = pa.pair_to_graph( sp3, sp4 ); g
g.vertices(sort=True)
g.edges(sort=True)
sage.combinat.partition_algebra.propagating_number(sp)[source]

Return the propagating number of the set partition sp.

The propagating number is the number of blocks with both a positive and negative number.

EXAMPLES:

sage: import sage.combinat.partition_algebra as pa
sage: sp1 = pa.to_set_partition([[1,-2],[2,-1]])
sage: sp2 = pa.to_set_partition([[1,2],[-2,-1]])
sage: pa.propagating_number(sp1)
2
sage: pa.propagating_number(sp2)
0
>>> from sage.all import *
>>> import sage.combinat.partition_algebra as pa
>>> sp1 = pa.to_set_partition([[Integer(1),-Integer(2)],[Integer(2),-Integer(1)]])
>>> sp2 = pa.to_set_partition([[Integer(1),Integer(2)],[-Integer(2),-Integer(1)]])
>>> pa.propagating_number(sp1)
2
>>> pa.propagating_number(sp2)
0
import sage.combinat.partition_algebra as pa
sp1 = pa.to_set_partition([[1,-2],[2,-1]])
sp2 = pa.to_set_partition([[1,2],[-2,-1]])
pa.propagating_number(sp1)
pa.propagating_number(sp2)
sage.combinat.partition_algebra.set_partition_composition(sp1, sp2)[source]

Return a tuple consisting of the composition of the set partitions sp1 and sp2 and the number of components removed from the middle rows of the graph.

EXAMPLES:

sage: # needs sage.graphs
sage: import sage.combinat.partition_algebra as pa
sage: sp1 = pa.to_set_partition([[1,-2],[2,-1]])
sage: sp2 = pa.to_set_partition([[1,-2],[2,-1]])
sage: pa.set_partition_composition(sp1, sp2) == (pa.identity(2), 0)
True
>>> from sage.all import *
>>> # needs sage.graphs
>>> import sage.combinat.partition_algebra as pa
>>> sp1 = pa.to_set_partition([[Integer(1),-Integer(2)],[Integer(2),-Integer(1)]])
>>> sp2 = pa.to_set_partition([[Integer(1),-Integer(2)],[Integer(2),-Integer(1)]])
>>> pa.set_partition_composition(sp1, sp2) == (pa.identity(Integer(2)), Integer(0))
True
# needs sage.graphs
import sage.combinat.partition_algebra as pa
sp1 = pa.to_set_partition([[1,-2],[2,-1]])
sp2 = pa.to_set_partition([[1,-2],[2,-1]])
pa.set_partition_composition(sp1, sp2) == (pa.identity(2), 0)
sage.combinat.partition_algebra.to_graph(sp)[source]

Return a graph representing the set partition sp.

EXAMPLES:

sage: # needs sage.graphs
sage: import sage.combinat.partition_algebra as pa
sage: g = pa.to_graph(pa.to_set_partition([[1,-2], [2,-1]])); g
Graph on 4 vertices
sage: g.vertices(sort=False)    # random
[1, 2, -2, -1]
sage: g.edges(sort=False)       # random
[(1, -2, None), (2, -1, None)]
>>> from sage.all import *
>>> # needs sage.graphs
>>> import sage.combinat.partition_algebra as pa
>>> g = pa.to_graph(pa.to_set_partition([[Integer(1),-Integer(2)], [Integer(2),-Integer(1)]])); g
Graph on 4 vertices
>>> g.vertices(sort=False)    # random
[1, 2, -2, -1]
>>> g.edges(sort=False)       # random
[(1, -2, None), (2, -1, None)]
# needs sage.graphs
import sage.combinat.partition_algebra as pa
g = pa.to_graph(pa.to_set_partition([[1,-2], [2,-1]])); g
g.vertices(sort=False)    # random
g.edges(sort=False)       # random
sage.combinat.partition_algebra.to_set_partition(l, k=None)[source]

Convert a list of a list of numbers to a set partitions.

Each list of numbers in the outer list specifies the numbers contained in one of the blocks in the set partition.

If k is specified, then the set partition will be a set partition of 1, …, k, -1, …, -k. Otherwise, k will default to the minimum number needed to contain all of the specified numbers.

EXAMPLES:

sage: import sage.combinat.partition_algebra as pa
sage: pa.to_set_partition([[1,-1],[2,-2]]) == pa.identity(2)
True
>>> from sage.all import *
>>> import sage.combinat.partition_algebra as pa
>>> pa.to_set_partition([[Integer(1),-Integer(1)],[Integer(2),-Integer(2)]]) == pa.identity(Integer(2))
True
import sage.combinat.partition_algebra as pa
pa.to_set_partition([[1,-1],[2,-2]]) == pa.identity(2)