隔墙#
- class sympy.combinatorics.partitions.Partition(*partition)[源代码]#
这个类表示一个抽象分区。
分拆是一组不相交的集,其并集等于给定集。
- property RGS#
返回分区的“限制增长字符串”。
解释
RGS以索引列表的形式返回,其中L [i] 指示元素i出现的块。例如,在一个由3个元素(a、b、c)组成2个块的分区中( [c] , [a, b] )RGS是 [1,1,0] :“a”在块1中,“b”在块1中,“c”在块0中。
实例
>>> from sympy.combinatorics import Partition >>> a = Partition([1, 2], [3], [4, 5]) >>> a.members (1, 2, 3, 4, 5) >>> a.RGS (0, 0, 1, 2, 2) >>> a + 1 Partition({3}, {4}, {5}, {1, 2}) >>> _.RGS (0, 0, 1, 2, 3)
- classmethod from_rgs(rgs, elements)[源代码]#
从限制增长字符串创建集合分区。
解释
在rgs中给出的指数被假定为元素中给定的元素的索引 按规定 (元素不按此例程排序)。块编号从0开始。如果没有在任何块中引用
rgs
将引发错误。实例
>>> from sympy.combinatorics import Partition >>> Partition.from_rgs([0, 1, 2, 0, 1], list('abcde')) Partition({c}, {a, d}, {b, e}) >>> Partition.from_rgs([0, 1, 2, 0, 1], list('cbead')) Partition({e}, {a, c}, {b, d}) >>> a = Partition([1, 4], [2], [3, 5]) >>> Partition.from_rgs(a.RGS, a.members) Partition({2}, {1, 4}, {3, 5})
- property partition#
将partition作为列表的排序列表返回。
实例
>>> from sympy.combinatorics import Partition >>> Partition([1], [2, 3]).partition [[1], [2, 3]]
- property rank#
获取分区的等级。
实例
>>> from sympy.combinatorics import Partition >>> a = Partition([1, 2], [3], [4, 5]) >>> a.rank 13
- sort_key(order=None)[源代码]#
返回可用于排序的规范键。
排序是基于分区的大小和排序的元素,并用秩来打破关系。
实例
>>> from sympy import default_sort_key >>> from sympy.combinatorics import Partition >>> from sympy.abc import x >>> a = Partition([1, 2]) >>> b = Partition([3, 4]) >>> c = Partition([1, x]) >>> d = Partition(list(range(4))) >>> l = [d, b, a + 1, a, c] >>> l.sort(key=default_sort_key); l [Partition({1, 2}), Partition({1}, {2}), Partition({1, x}), Partition({3, 4}), Partition({0, 1, 2, 3})]
- class sympy.combinatorics.partitions.IntegerPartition(partition, integer=None)[源代码]#
此类表示整数分区。
解释
在数论和组合学中,一个正整数的划分,
n
,也称为整数分区,是一种写入方式n
作为一个和为n的正整数的列表,两个只在求和顺序上不同的分区被认为是同一个分区;如果顺序很重要,则这些分区称为合成。例如,4有五个分区: [4] , [3, 1] , [2, 2] , [2,1,1] 和 [1,1,1,1] ;成分 [1,2,1] 和 [1,1,2] 与分区相同 [2,1,1] .工具书类
- as_dict()[源代码]#
将分区作为字典返回,其键是分区整数,值是该整数的重数。
实例
>>> from sympy.combinatorics.partitions import IntegerPartition >>> IntegerPartition([1]*3 + [2] + [3]*4).as_dict() {1: 3, 2: 1, 3: 4}
- as_ferrers(char='#')[源代码]#
打印分区的ferrer图。
实例
>>> from sympy.combinatorics.partitions import IntegerPartition >>> print(IntegerPartition([1, 1, 5]).as_ferrers()) ##### # #
- property conjugate#
计算它自身的共轭分划。
实例
>>> from sympy.combinatorics.partitions import IntegerPartition >>> a = IntegerPartition([6, 3, 3, 2, 1]) >>> a.conjugate [5, 4, 3, 1, 1, 1]
- sympy.combinatorics.partitions.random_integer_partition(n, seed=None)[源代码]#
整数和生成随机分区
n
作为反向排序的整数列表。实例
>>> from sympy.combinatorics.partitions import random_integer_partition
对于以下情况,给定一个种子以便可以显示已知的值;实际上,不会给出种子。
>>> random_integer_partition(100, seed=[1, 1, 12, 1, 2, 1, 85, 1]) [85, 12, 2, 1] >>> random_integer_partition(10, seed=[1, 2, 3, 1, 5, 1]) [5, 3, 1, 1] >>> random_integer_partition(1) [1]
- sympy.combinatorics.partitions.RGS_generalized(m)[源代码]#
计算m+1广义无限制增长字符串,并将其作为矩阵中的行返回。
实例
>>> from sympy.combinatorics.partitions import RGS_generalized >>> RGS_generalized(6) Matrix([ [ 1, 1, 1, 1, 1, 1, 1], [ 1, 2, 3, 4, 5, 6, 0], [ 2, 5, 10, 17, 26, 0, 0], [ 5, 15, 37, 77, 0, 0, 0], [ 15, 52, 151, 0, 0, 0, 0], [ 52, 203, 0, 0, 0, 0, 0], [203, 0, 0, 0, 0, 0, 0]])
- sympy.combinatorics.partitions.RGS_enum(m)[源代码]#
RGS_enum计算大小为m的超集可能的限制增长字符串的总数。
实例
>>> from sympy.combinatorics.partitions import RGS_enum >>> from sympy.combinatorics import Partition >>> RGS_enum(4) 15 >>> RGS_enum(5) 52 >>> RGS_enum(6) 203
我们可以通过实际生成分区来检查枚举是否正确。在这里,将生成4个项目的15个分区:
>>> a = Partition(list(range(4))) >>> s = set() >>> for i in range(20): ... s.add(a) ... a += 1 ... >>> assert len(s) == 15